-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add
pick
and omit
methods to InterfaceType
These methods provide features similar to TypeScript's builtin `Pick` and `Omit` types. Co-Authored-By: Robin Kneepkens <robin@skunk.team>
- Loading branch information
Showing
24 changed files
with
752 additions
and
188 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,8 @@ | |
|
||
## FullType type | ||
|
||
Result of the [object()](./types.object.md) function. | ||
|
||
**Signature:** | ||
|
||
```typescript | ||
|
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,21 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [@skunkteam/types](./types.md) > [InterfacePickOptions](./types.interfacepickoptions.md) > [applyParser](./types.interfacepickoptions.applyparser.md) | ||
|
||
## InterfacePickOptions.applyParser property | ||
|
||
Choose whether to apply the custom parser from the base type onto the newly "picked type" or not. | ||
|
||
**Signature:** | ||
|
||
```typescript | ||
applyParser?: boolean; | ||
``` | ||
|
||
## Remarks | ||
|
||
By default, custom parsers (i.e. parsers that are added to a type using [BaseTypeImpl.withParser()](./types.basetypeimpl.withparser.md) or [BaseTypeImpl.autoCast](./types.basetypeimpl.autocast.md)<!-- -->) are not reused when a new type is created using [InterfaceType.pick()](./types.interfacetype.pick.md) and [InterfaceType.omit()](./types.interfacetype.omit.md)<!-- -->. | ||
|
||
However, it is possible to reuse a parser that is set on the base type. Parsers have a single input of type `unknown` and may produce anything (also with type `unknown`<!-- -->). The result of a parser will always be validated afterwards by the type it is applied to. Technically, any parser is applicable to any type, but it might not make sense to do so. Therefore, you can choose to apply it or not with this option. | ||
|
||
If a custom parser is found on the base type, then this options is mandatory. |
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,21 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [@skunkteam/types](./types.md) > [InterfacePickOptions](./types.interfacepickoptions.md) | ||
|
||
## InterfacePickOptions interface | ||
|
||
Options for [InterfaceType.pick()](./types.interfacetype.pick.md) and [InterfaceType.omit()](./types.interfacetype.omit.md)<!-- -->. | ||
|
||
**Signature:** | ||
|
||
```typescript | ||
interface InterfacePickOptions | ||
``` | ||
|
||
## Properties | ||
|
||
| Property | Modifiers | Type | Description | | ||
| ------------------------------------------------------------------- | --------- | -------------- | ---------------------------------------------------------------------------------------------------------------- | | ||
| [applyParser?](./types.interfacepickoptions.applyparser.md) | | boolean | _(Optional)_ Choose whether to apply the custom parser from the base type onto the newly "picked type" or not. | | ||
| [name?](./types.interfacepickoptions.name.md) | | string \| null | _(Optional)_ The optional name for the new type, or <code>null</code> to force a generated TypeScript-like name. | | ||
| [omitValidations?](./types.interfacepickoptions.omitvalidations.md) | | true | _(Optional)_ Suppress the error about existing custom validations on the base type. | |
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,19 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [@skunkteam/types](./types.md) > [InterfacePickOptions](./types.interfacepickoptions.md) > [name](./types.interfacepickoptions.name.md) | ||
|
||
## InterfacePickOptions.name property | ||
|
||
The optional name for the new type, or `null` to force a generated TypeScript-like name. | ||
|
||
**Signature:** | ||
|
||
```typescript | ||
name?: string | null; | ||
``` | ||
|
||
## Remarks | ||
|
||
When omitted, it will follow the name of original type (on the left). It will either use the custom name of that type or generate a new default TypeScript-like name if the type did not have a custom name. | ||
|
||
Use this `name` setting with a `string` to provide a new custom name or use `null` to force a generated TypeScript-like name, even if the original type has a custom name. |
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,21 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [@skunkteam/types](./types.md) > [InterfacePickOptions](./types.interfacepickoptions.md) > [omitValidations](./types.interfacepickoptions.omitvalidations.md) | ||
|
||
## InterfacePickOptions.omitValidations property | ||
|
||
Suppress the error about existing custom validations on the base type. | ||
|
||
**Signature:** | ||
|
||
```typescript | ||
omitValidations?: true; | ||
``` | ||
|
||
## Remarks | ||
|
||
Validations are not reused when picking or omitting properties from a base type. This is because validations work on the original base type. The new type, with some properties omitted, is not assignable to the original type. Therefore, we cannot reliably call the validations with instances of the new type. | ||
|
||
When a custom validation is encountered by Skunk Team types, an Error will be thrown. Use this option to ignore the validations and continue with the pick or omit operation. | ||
|
||
This is to ensure that custom validations are never accidentally lost. |
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
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 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [@skunkteam/types](./types.md) > [InterfaceType](./types.interfacetype.md) > [omit](./types.interfacetype.omit.md) | ||
|
||
## InterfaceType.omit() method | ||
|
||
Create a new type that consists of all properties of the base type, except those mentioned, similar to the builtin `Omit` type. | ||
|
||
**Signature:** | ||
|
||
```typescript | ||
omit<const Key extends keyof Props & keyof ResultType & string>(...args: [keys: OneOrMore<Key>] | [name: string, keys: OneOrMore<Key>] | [options: InterfacePickOptions, keys: OneOrMore<Key>]): PickType<Props, ResultType, Exclude<keyof Props & keyof ResultType & string, Key>>; | ||
``` | ||
## Parameters | ||
| Parameter | Type | Description | | ||
| --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------- | | ||
| args | \[keys: [OneOrMore](./types.oneormore.md)<!-- --><Key>\] \| \[name: string, keys: [OneOrMore](./types.oneormore.md)<!-- --><Key>\] \| \[options: [InterfacePickOptions](./types.interfacepickoptions.md)<!-- -->, keys: [OneOrMore](./types.oneormore.md)<!-- --><Key>\] | | | ||
**Returns:** | ||
[PickType](./types.picktype.md)<!-- --><Props, ResultType, Exclude<keyof Props & keyof ResultType & string, Key>> |
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 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [@skunkteam/types](./types.md) > [InterfaceType](./types.interfacetype.md) > [pick](./types.interfacetype.pick.md) | ||
|
||
## InterfaceType.pick() method | ||
|
||
Create a new type that consists only of the mentioned properties similar to the builtin `Pick` type. | ||
|
||
**Signature:** | ||
|
||
```typescript | ||
pick<const Key extends keyof Props & keyof ResultType & string>(...args: [keys: OneOrMore<Key>] | [name: string, keys: OneOrMore<Key>] | [options: InterfacePickOptions, keys: OneOrMore<Key>]): PickType<Props, ResultType, Key>; | ||
``` | ||
## Parameters | ||
| Parameter | Type | Description | | ||
| --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------- | | ||
| args | \[keys: [OneOrMore](./types.oneormore.md)<!-- --><Key>\] \| \[name: string, keys: [OneOrMore](./types.oneormore.md)<!-- --><Key>\] \| \[options: [InterfacePickOptions](./types.interfacepickoptions.md)<!-- -->, keys: [OneOrMore](./types.oneormore.md)<!-- --><Key>\] | | | ||
**Returns:** | ||
[PickType](./types.picktype.md)<!-- --><Props, ResultType, Key> |
Oops, something went wrong.