mobx-keystone-mindreframer
Version:
A MobX powered state management solution based on data trees with first class support for Typescript, snapshots, patches and much more
32 lines (29 loc) • 926 B
text/typescript
/**
* @ignore
*
* A primitive value.
*/
export type PrimitiveValue = undefined | null | boolean | number | string | bigint
/**
* @ignore
*
* Checks if a value is optional (undefined, any or unknown).
*
* Examples:
* - string = false
* - undefined = true
* - string | undefined = true
* - string & undefined = false, but we don't care
* - any = true
* - unknown = true
* - null = false
* - string | null = false
* - string & null = false
*/
export type IsOptionalValue<C, TV, FV> = undefined extends C ? TV : FV
// type _A = IsOptionalValue<string, true, false> // false
// type _B = IsOptionalValue<undefined, true, false> // true
// type _C = IsOptionalValue<string | undefined, true, false> // true
// type _D = IsOptionalValue<string & undefined, true, false> // false, but we don't care
// type _E = IsOptionalValue<any, true, false> // true
// type _F = IsOptionalValue<unknown, true, false> // true