Skip to content

Commit b5954c1

Browse files
authored
types: use node: prefix for builtins (fastify#5896)
1 parent 8e27e22 commit b5954c1

18 files changed

+38
-38
lines changed

docs/Reference/TypeScript.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -873,8 +873,8 @@ a more detailed http server walkthrough.
873873
874874
1. Create the following imports from `@types/node` and `fastify`
875875
```typescript
876-
import fs from 'fs'
877-
import path from 'path'
876+
import fs from 'node:fs'
877+
import path from 'node:path'
878878
import fastify from 'fastify'
879879
```
880880
2. Perform the following steps before setting up a Fastify HTTPS server
@@ -935,7 +935,7 @@ specified at server instantiation, the custom type becomes available on all
935935
further instances of the custom type.
936936
```typescript
937937
import fastify from 'fastify'
938-
import http from 'http'
938+
import http from 'node:http'
939939
940940
interface customRequest extends http.IncomingMessage {
941941
mySpecialProp: string
@@ -1123,8 +1123,8 @@ returns `http.IncomingMessage`, otherwise, it returns
11231123
`http2.Http2ServerRequest`.
11241124
11251125
```typescript
1126-
import http from 'http'
1127-
import http2 from 'http2'
1126+
import http from 'node:http'
1127+
import http2 from 'node:http2'
11281128
import { RawRequestDefaultExpression } from 'fastify'
11291129
11301130
RawRequestDefaultExpression<http.Server> // -> http.IncomingMessage
@@ -1183,8 +1183,8 @@ returns `http.ServerResponse`, otherwise, it returns
11831183
`http2.Http2ServerResponse`.
11841184
11851185
```typescript
1186-
import http from 'http'
1187-
import http2 from 'http2'
1186+
import http from 'node:http'
1187+
import http2 from 'node:http2'
11881188
import { RawReplyDefaultExpression } from 'fastify'
11891189
11901190
RawReplyDefaultExpression<http.Server> // -> http.ServerResponse

examples/typescript-server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*/
1212

1313
import fastify, { FastifyInstance, RouteShorthandOptions } from '../fastify'
14-
import { Server, IncomingMessage, ServerResponse } from 'http'
14+
import { Server, IncomingMessage, ServerResponse } from 'node:http'
1515

1616
// Create an http server. We pass the relevant typings for our http version used.
1717
// By passing types we get correctly typed access to the underlying http objects in routes.

fastify.d.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import * as http from 'http'
2-
import * as http2 from 'http2'
3-
import * as https from 'https'
4-
import { Socket } from 'net'
1+
import * as http from 'node:http'
2+
import * as http2 from 'node:http2'
3+
import * as https from 'node:https'
4+
import { Socket } from 'node:net'
55

66
import { Options as AjvOptions, ValidatorFactory } from '@fastify/ajv-compiler'
77
import { FastifyError } from '@fastify/error'

test/types/content-type-parser.test-d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import fastify, { FastifyBodyParser } from '../../fastify'
22
import { expectError, expectType } from 'tsd'
3-
import { IncomingMessage } from 'http'
3+
import { IncomingMessage } from 'node:http'
44
import { FastifyRequest } from '../../types/request'
55

66
expectType<void>(fastify().addContentTypeParser('contentType', function (request, payload, done) {

test/types/fastify.test-d.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { ErrorObject as AjvErrorObject } from 'ajv'
2-
import * as http from 'http'
3-
import * as http2 from 'http2'
4-
import * as https from 'https'
5-
import { Socket } from 'net'
2+
import * as http from 'node:http'
3+
import * as http2 from 'node:http2'
4+
import * as https from 'node:https'
5+
import { Socket } from 'node:net'
66
import { expectAssignable, expectError, expectNotAssignable, expectType } from 'tsd'
77
import fastify, {
88
ConnectionError,

test/types/instance.test-d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { HookHandlerDoneFunction } from '../../types/hooks'
1313
import { FastifyReply } from '../../types/reply'
1414
import { FastifyRequest } from '../../types/request'
1515
import { FastifySchemaControllerOptions, FastifySchemaCompiler, FastifySerializerCompiler } from '../../types/schema'
16-
import { AddressInfo } from 'net'
16+
import { AddressInfo } from 'node:net'
1717
import { Bindings, ChildLoggerOptions } from '../../types/logger'
1818

1919
const server = fastify()

test/types/logger.test-d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import fastify, {
77
FastifyReply,
88
FastifyBaseLogger
99
} from '../../fastify'
10-
import { Server, IncomingMessage, ServerResponse } from 'http'
11-
import * as fs from 'fs'
10+
import { Server, IncomingMessage, ServerResponse } from 'node:http'
11+
import * as fs from 'node:fs'
1212
import P from 'pino'
1313
import { ResSerializerReply } from '../../types/logger'
1414

test/types/plugin.test-d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import fastify, { FastifyInstance, FastifyPluginOptions, SafePromiseLike } from '../../fastify'
2-
import * as http from 'http'
3-
import * as https from 'https'
2+
import * as http from 'node:http'
3+
import * as https from 'node:https'
44
import { expectType, expectError, expectAssignable } from 'tsd'
55
import { FastifyPluginCallback, FastifyPluginAsync } from '../../types/plugin'
66
import { FastifyError } from '@fastify/error'

test/types/register.test-d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { expectAssignable, expectError, expectType } from 'tsd'
2-
import { IncomingMessage, Server, ServerResponse } from 'http'
3-
import { Http2Server, Http2ServerRequest, Http2ServerResponse } from 'http2'
2+
import { IncomingMessage, Server, ServerResponse } from 'node:http'
3+
import { Http2Server, Http2ServerRequest, Http2ServerResponse } from 'node:http2'
44
import fastify, { FastifyInstance, FastifyError, FastifyLoggerInstance, FastifyPluginAsync, FastifyPluginCallback, FastifyPluginOptions, RawServerDefault } from '../../fastify'
55

66
const testPluginCallback: FastifyPluginCallback = function (instance, opts, done) { }

test/types/reply.test-d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Buffer } from 'buffer'
1+
import { Buffer } from 'node:buffer'
22
import { expectAssignable, expectError, expectType } from 'tsd'
33
import fastify, { FastifyContextConfig, FastifyReply, FastifyRequest, FastifySchema, FastifyTypeProviderDefault, RawRequestDefaultExpression, RouteHandler, RouteHandlerMethod } from '../../fastify'
44
import { FastifyInstance } from '../../types/instance'

test/types/route.test-d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { FastifyError } from '@fastify/error'
2-
import * as http from 'http'
2+
import * as http from 'node:http'
33
import { expectAssignable, expectError, expectType } from 'tsd'
44
import fastify, { FastifyInstance, FastifyReply, FastifyRequest, RouteHandlerMethod } from '../../fastify'
55
import { RequestPayload } from '../../types/hooks'

test/types/serverFactory.test-d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import fastify, { FastifyServerFactory } from '../../fastify'
2-
import * as http from 'http'
2+
import * as http from 'node:http'
33
import { expectType } from 'tsd'
44

55
// Custom Server

test/types/type-provider.test-d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import fastify, {
88
SafePromiseLike
99
} from '../../fastify'
1010
import { expectAssignable, expectError, expectType } from 'tsd'
11-
import { IncomingHttpHeaders } from 'http'
11+
import { IncomingHttpHeaders } from 'node:http'
1212
import { Type, TSchema, Static } from '@sinclair/typebox'
1313
import { FromSchema, JSONSchema } from 'json-schema-to-ts'
1414

types/hooks.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Readable } from 'stream'
1+
import { Readable } from 'node:stream'
22
import { FastifyInstance } from './instance'
33
import { RouteOptions, RouteGenericInterface } from './route'
44
import { RawServerBase, RawServerDefault, RawRequestDefaultExpression, RawReplyDefaultExpression, ContextConfigDefault } from './utils'

types/instance.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { FastifyError } from '@fastify/error'
22
import { ConstraintStrategy, FindResult, HTTPVersion } from 'find-my-way'
3-
import * as http from 'http'
3+
import * as http from 'node:http'
44
import { InjectOptions, CallbackFunc as LightMyRequestCallback, Chain as LightMyRequestChain, Response as LightMyRequestResponse } from 'light-my-request'
5-
import { AddressInfo } from 'net'
5+
import { AddressInfo } from 'node:net'
66
import { AddContentTypeParser, ConstructorAction, FastifyBodyParser, ProtoAction, getDefaultJsonParser, hasContentTypeParser, removeAllContentTypeParsers, removeContentTypeParser } from './content-type-parser'
77
import { ApplicationHook, HookAsyncLookup, HookLookup, LifecycleHook, onCloseAsyncHookHandler, onCloseHookHandler, onErrorAsyncHookHandler, onErrorHookHandler, onListenAsyncHookHandler, onListenHookHandler, onReadyAsyncHookHandler, onReadyHookHandler, onRegisterHookHandler, onRequestAbortAsyncHookHandler, onRequestAbortHookHandler, onRequestAsyncHookHandler, onRequestHookHandler, onResponseAsyncHookHandler, onResponseHookHandler, onRouteHookHandler, onSendAsyncHookHandler, onSendHookHandler, onTimeoutAsyncHookHandler, onTimeoutHookHandler, preCloseAsyncHookHandler, preCloseHookHandler, preHandlerAsyncHookHandler, preHandlerHookHandler, preParsingAsyncHookHandler, preParsingHookHandler, preSerializationAsyncHookHandler, preSerializationHookHandler, preValidationAsyncHookHandler, preValidationHookHandler } from './hooks'
88
import { FastifyBaseLogger, FastifyChildLoggerFactory } from './logger'

types/reply.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Buffer } from 'buffer'
1+
import { Buffer } from 'node:buffer'
22
import { FastifyInstance } from './instance'
33
import { FastifyBaseLogger } from './logger'
44
import { FastifyRequest, RequestRouteOptions } from './request'

types/serverFactory.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { RawServerBase, RawServerDefault, RawReplyDefaultExpression, RawRequestDefaultExpression } from './utils'
2-
import * as http from 'http'
3-
import * as https from 'https'
4-
import * as http2 from 'http2'
2+
import * as http from 'node:http'
3+
import * as https from 'node:https'
4+
import * as http2 from 'node:http2'
55

66
export type FastifyServerFactoryHandler<
77
RawServer extends RawServerBase = RawServerDefault,

types/utils.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import * as http from 'http'
2-
import * as http2 from 'http2'
3-
import * as https from 'https'
1+
import * as http from 'node:http'
2+
import * as http2 from 'node:http2'
3+
import * as https from 'node:https'
44

55
type AutocompletePrimitiveBaseType<T> =
66
T extends string ? string :

0 commit comments

Comments
 (0)