TypeScript Configuration
You can customize the behavior of the TypeScript SDK generator in generators.yml
:
SDK configuration options
allowExtraFields
Allow fields that are not defined in object schemas. This only applies to serde.
bundle
defaultTimeoutInSeconds
The default timeout for network requests. In the generated client, this can be overridden at the request level.
enableInlineTypes
When enabled, the inline schemas will be generated as nested types in TypeScript. This results in cleaner type names and a more intuitive developer experience.
enableInlineTypes: false
:
enableInlineTypes: true
:
Now users can get the deep nested Bar
type as follows:
extraDependencies
Specify extra dependencies in the generated package.json
. This is useful
when you utilize .fernignore
to
supplement the generated client with custom code.
extraDevDependencies
Specify extra dev dependencies in the generated package.json
.
extraPeerDependencies
Specify extra peer dependencies in the generated package.json
:
extraPeerDependenciesMeta
Specify extra peer dependencies meta fields in the generated package.json
:
fetchSupport
Choose whether you want to include node-fetch
to support Node.js versions before Node.js 18, or choose native
to use the native fetch
API available in Node.js 18 and later.
fileResponseType
Change the type of response returned to the user for a binary HTTP response:
stream
: Returns a stream. SeestreamType
, which controls the type of stream returned.binary-response
: Returns theBinaryResponse
type, which allows the user to choose how to consume the binary HTTP response. Here’s how your users can interact with theBinaryResponse
:
formDataSupport
Choose whether you want to support Node.js 16 and above (Node16
), or Node.js 18 and above (Node18
).
Node16
uses multiple dependencies to support multipart forms, includingform-data
,formdata-node
, andform-data-encoder
.Node18
uses the native FormData API, and accepts a wider range of types for file uploads, such asBuffer
,File
,Blob
,Readable
,ReadableStream
,ArrayBuffer
, andUint8Array
includeContentHeadersOnFileDownloadResponse
Includes the content type and content length from binary responses. The user will receive an object of the following type:
<BINARY_RESPONSE_TYPE>
is core.BinaryResponse
or a stream, depending on fileResponseType
setting.
includeCredentialsOnCrossOriginRequests
When enabled, withCredentials
is set to true
when making network requests.
includeOtherInUnionTypes
includeUtilsOnUnionMembers
inlineFileProperties
Generate file upload properties as inline request properties (instead of positional parameters).
inlineFileProperties: false
:
inlineFileProperties: true
:
inlinePathParameters
Inline path parameters into request types.
inlinePathParameters: false
:
inlinePathParameters: true
:
namespaceExport
By default, names are based on the organization and API names in the Fern Definition:
namespaceExport
customizes the exported namespace and client names:
neverThrowErrors
When enabled, the client doesn’t throw errors when a non-200 response is received from the server. Instead, the response is wrapped in an ApiResponse
.
noOptionalProperties
By default, Fern’s optional<>
properties will translate to optional TypeScript properties:
When noOptionalProperties
is enabled, the generated properties are never optional. Instead, the type is generated with | undefined
. As a result, users must explicitly set the property to a value or undefined
.
noScripts
Prevent the generator from running any scripts such as yarn format
or yarn install
. If any of the scripts cause errors, toggling this option will allow you to receive the generated code.
noSerdeLayer
No serialization/deserialization code is generated by default. The client uses JSON.parse()
and JSON.stringify()
instead of the default Serde layer.
When noSerdeLayer: false
, the generated client includes a layer for serializing requests and deserializing responses. This has three benefits:
-
The client validates requests and response at runtime (client-side).
-
The client can support complex types like
Date
andSet
. -
The generated types can stray from the wire/JSON representation to be more idiomatic. For example, when the Serde layer is enabled (
noSerdeLayer: false
), all properties arecamelCase
, even if the server is expectingsnake_case
.
outputSourceFiles
When enabled, the generator outputs raw TypeScript files. When disabled (the default), outputs .js
and d.ts
files.
packageJson
When you specify an object in packageJson
, it will be merged into the package.json
file.
packagePath
Specify the path where the source files for the generated SDK should be placed.
publishToJsr
Publish your SDK to JSR. When enabled, the generator will
generate a jsr.json
as well as a GitHub workflow to publish to JSR.
retainOriginalCasing
When enabled, property names in the generated code retain their original casing from the API definition instead of being converted to camelCase.
Example with OpenAPI input:
Generated TypeScript with retainOriginalCasing: true
:
Generated TypeScript with default settings (retainOriginalCasing: false
):
shouldGenerateWebsocketClients
Generate WebSocket clients from your AsyncAPI specs.
skipResponseValidation
By default, the client will throw an error if the response from the server doesn’t match the expected type (based on how the response is modeled in the Fern Definition).
If skipResponseValidation
is set to true
, the client will never throw if the response is misshapen. Instead, the client will log the issue using console.warn
and return the data (casted to the expected response type).
noSerdeLayer: false
). The Serde layer is disabled by default (noSerdeLayer: true
).streamType
Change the type of stream that is used in the generated SDK.
wrapper
: The streams use a wrapper with multiple underlying implementations to support versions of Node.js before Node.js 18.web
: The streams use the web standardReadableStream
.
The default is web
.
treatUnknownAsAny
When treatUnknownAsAny
is enabled, unknown types from Fern are generated into TypeScript using any
instead of the unknown
type.
useBigInt
When useBigInt
is set to true
, a customized JSON serializer & deserializer is used that will preserve the precision of bigint
’s, as opposed to the native JSON.stringify
and JSON.parse
function which converts bigint
’s to number’s losing precision.
When combining useBigInt
with our serialization layer (no-serde: false
), both the request and response properties that are marked as long
and bigint
in OpenAPI/Fern spec, will consistently be bigint
’s.
However, when disabling the serialization layer (no-serde: true
), they will be typed as number | bigint
.
Here’s an overview of what to expect from the generated types when combining useBigInt
and noSerde
with the following Fern definition:
Fern definition:
TypeScript output:
useBrandedStringAliases
When useBrandedStringAliases
is disabled (the default), string aliases are generated as
normal TypeScript aliases:
When useBrandedStringAliases
is enabled, string aliases are generated as branded strings. This makes each alias feel like its own type and improves compile-time safety.