-
-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix output type of nullable, nullish and optional #593
- Loading branch information
1 parent
49bb406
commit dde5687
Showing
14 changed files
with
94 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './nullable.ts'; | ||
export * from './nullableAsync.ts'; | ||
export * from './types.ts'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import type { | ||
BaseIssue, | ||
BaseSchema, | ||
BaseSchemaAsync, | ||
DefaultAsync, | ||
DefaultValue, | ||
InferOutput, | ||
NonNullable, | ||
} from '../../types/index.ts'; | ||
|
||
/** | ||
* Infer nullable output type. | ||
*/ | ||
export type InferNullableOutput< | ||
TWrapped extends | ||
| BaseSchema<unknown, unknown, BaseIssue<unknown>> | ||
| BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>, | ||
TDefault extends DefaultAsync<TWrapped, undefined>, | ||
> = [TDefault] extends [never] | ||
? InferOutput<TWrapped> | null | ||
: // FIXME: For schemas that transform the input to `undefined`, this | ||
// implementation may result in an incorrect output type | ||
NonNullable<InferOutput<TWrapped>> | Extract<DefaultValue<TDefault>, null>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './nullish.ts'; | ||
export * from './nullishAsync.ts'; | ||
export * from './types.ts'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import type { | ||
BaseIssue, | ||
BaseSchema, | ||
BaseSchemaAsync, | ||
DefaultAsync, | ||
DefaultValue, | ||
InferOutput, | ||
NonNullish, | ||
} from '../../types/index.ts'; | ||
|
||
/** | ||
* Infer nullish output type. | ||
*/ | ||
export type InferNullishOutput< | ||
TWrapped extends | ||
| BaseSchema<unknown, unknown, BaseIssue<unknown>> | ||
| BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>, | ||
TDefault extends DefaultAsync<TWrapped, undefined>, | ||
> = [TDefault] extends [never] | ||
? InferOutput<TWrapped> | null | undefined | ||
: // FIXME: For schemas that transform the input to `undefined`, this | ||
// implementation may result in an incorrect output type | ||
| NonNullish<InferOutput<TWrapped>> | ||
| Extract<DefaultValue<TDefault>, null | undefined>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './optional.ts'; | ||
export * from './optionalAsync.ts'; | ||
export * from './types.ts'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import type { | ||
BaseIssue, | ||
BaseSchema, | ||
BaseSchemaAsync, | ||
DefaultAsync, | ||
DefaultValue, | ||
InferOutput, | ||
NonOptional, | ||
} from '../../types/index.ts'; | ||
|
||
/** | ||
* Infer optional output type. | ||
*/ | ||
export type InferOptionalOutput< | ||
TWrapped extends | ||
| BaseSchema<unknown, unknown, BaseIssue<unknown>> | ||
| BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>, | ||
TDefault extends DefaultAsync<TWrapped, undefined>, | ||
> = [TDefault] extends [never] | ||
? InferOutput<TWrapped> | undefined | ||
: // FIXME: For schemas that transform the input to `undefined`, this | ||
// implementation may result in an incorrect output type | ||
| NonOptional<InferOutput<TWrapped>> | ||
| Extract<DefaultValue<TDefault>, undefined>; |