-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3629 from GMOD/configuration-typescript
typescript checking for config slot names
- Loading branch information
Showing
46 changed files
with
282 additions
and
115 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
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,65 @@ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
import type { IStateTreeNode, Instance } from 'mobx-state-tree' | ||
import type { | ||
ConfigurationSchemaType, | ||
ConfigurationSchemaOptions, | ||
} from './configurationSchema' | ||
import type ConfigSlot from './configurationSlot' | ||
|
||
export type GetOptions<SCHEMA> = SCHEMA extends ConfigurationSchemaType< | ||
any, | ||
infer OPTIONS | ||
> | ||
? OPTIONS | ||
: never | ||
|
||
// type GetDefinition<SCHEMA> = SCHEMA extends ConfigurationSchemaType< | ||
// infer D, | ||
// any | ||
// > | ||
// ? D | ||
// : never | ||
|
||
export type GetBase<SCHEMA> = SCHEMA extends undefined | ||
? never | ||
: GetOptions<SCHEMA> extends ConfigurationSchemaOptions<undefined, any> | ||
? undefined | ||
: GetOptions<SCHEMA> extends ConfigurationSchemaOptions< | ||
infer BASE extends AnyConfigurationSchemaType, | ||
any | ||
> | ||
? BASE | ||
: never | ||
|
||
export type GetExplicitIdentifier<SCHEMA> = | ||
GetOptions<SCHEMA> extends ConfigurationSchemaOptions< | ||
any, | ||
infer EXPLICIT_IDENTIFIER extends string | ||
> | ||
? EXPLICIT_IDENTIFIER | ||
: never | ||
|
||
export type ConfigurationSchemaForModel<MODEL> = MODEL extends IStateTreeNode< | ||
infer SCHEMA extends AnyConfigurationSchemaType | ||
> | ||
? SCHEMA | ||
: never | ||
|
||
export type ConfigurationSlotName<SCHEMA> = SCHEMA extends undefined | ||
? never | ||
: SCHEMA extends ConfigurationSchemaType<infer D, any> | ||
? | ||
| (keyof D & string) | ||
| GetExplicitIdentifier<SCHEMA> | ||
| (GetBase<SCHEMA> extends ConfigurationSchemaType<any, any> | ||
? ConfigurationSlotName<GetBase<SCHEMA>> | ||
: never) | ||
: never | ||
|
||
export type AnyConfigurationSchemaType = ConfigurationSchemaType<any, any> | ||
export type AnyConfigurationModel = Instance<AnyConfigurationSchemaType> | ||
export type AnyConfigurationSlotType = ReturnType<typeof ConfigSlot> | ||
export type AnyConfigurationSlot = Instance<AnyConfigurationSlotType> | ||
|
||
export type ConfigurationModel<SCHEMA extends AnyConfigurationSchemaType> = | ||
Instance<SCHEMA> |
Oops, something went wrong.