You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
By default, Fern's `optional<>` properties will translate to optional TypeScript properties:
296
322
297
-
```yaml {4}
298
-
Person:
299
-
properties:
300
-
name: string
301
-
age: optional<integer>
302
-
```
303
-
304
-
```typescript {3}
305
-
interface Person {
306
-
name: string;
307
-
age?: number;
308
-
}
309
-
```
310
-
311
-
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`.
312
-
313
-
```typescript {3}
314
-
interface Person {
315
-
name: string;
316
-
age: number | undefined;
317
-
}
318
-
```
323
+
```yaml {4}
324
+
Person:
325
+
properties:
326
+
name: string
327
+
age: optional<integer>
328
+
```
329
+
330
+
```typescript {3}
331
+
interface Person {
332
+
name: string;
333
+
age?: number;
334
+
}
335
+
```
336
+
337
+
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`.
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.
No serialization/deserialization code is generated by default. The client uses `JSON.parse()` and `JSON.stringify()` instead of the default Serde layer.
328
353
329
-
When `noSerdeLayer: false`, the generated client includes a layer for serializing requests and deserializing responses. This has three benefits:
330
-
331
-
1. The client validates requests and response at runtime (client-side).
354
+
When `noSerdeLayer: false`, the generated client includes a layer for serializing requests and deserializing responses. This has three benefits:
332
355
333
-
1. The client can support complex types like `Date` and `Set`.
356
+
1. The client validates requests and response at runtime (client-side).
334
357
335
-
1. The generated types can stray from the wire/JSON representation to be more
336
-
idiomatic. For example, when the Serde layer is enabled (`noSerdeLayer: false`), all properties are `camelCase`, even if the server is expecting `snake_case`.
358
+
2. The client can support complex types like `Date` and `Set`.
337
359
360
+
3. 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 are `camelCase`, even if the server is expecting `snake_case`.
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).
424
446
425
447
<Warning>Response validation only occurs when the Serde layer is enabled (`noSerdeLayer: false`). The Serde layer is disabled by default (`noSerdeLayer: true`).</Warning>
When `treatUnknownAsAny` is enabled, [unknown types from Fern are generated into TypeScript using `any` instead of the `unknown` type](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-0.html#new-unknown-top-type).
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.
444
-
445
-
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.
446
-
However, when disabling the serialization layer (`no-serde: true`), they will be typed as `number | bigint`.
447
-
448
-
Here's an overview of what to expect from the generated types when combining `useBigInt` and `noSerde` with the following Fern definition:
When `useBrandedStringAliases` is disabled (the default), string aliases are generated as
496
-
normal TypeScript aliases:
497
-
498
-
```typescript
499
-
// generated code
500
-
501
-
export type MyString = string;
502
-
503
-
export type OtherString = string;
504
-
```
505
-
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.
506
-
507
-
```yaml
508
-
# fern definition
509
-
510
-
types:
511
-
MyString: string
512
-
OtherString: string
513
-
```
514
-
515
-
```typescript
516
-
// generated code
517
-
518
-
export type MyString = string & { __MyString: void };
519
-
export const MyString = (value: string): MyString => value as MyString;
520
-
521
-
export type OtherString = string & { __OtherString: void };
522
-
export const OtherString = (value: string): OtherString => value as OtherString;
523
-
```
524
-
525
-
```typescript
526
-
// consuming the generated type
527
-
528
-
function printMyString(s: MyString): void {
529
-
console.log("MyString: " + s);
530
-
}
531
-
532
-
// doesn't compile, "foo" is not assignable to MyString
533
-
printMyString("foo");
534
-
535
-
const otherString = OtherString("other-string");
536
-
// doesn't compile, otherString is not assignable to MyString
0 commit comments