Cheat Sheet
Assume Animal
is defined as in the Introduction
typescript
// importimport {Animal} from '...';// createconst steve = Animal.snake('steve');// snake typetype SnakeType = Animal<'snake'>;// union of all animalstype AllAnimalsType = Animal;
typescript
// importimport {Animal} from '...';// createconst steve = Animal.snake('steve');// snake typetype SnakeType = Animal<'snake'>;// union of all animalstype AllAnimalsType = Animal;
Snippets​
Here are some VS Code snippets to make it easier to write the type annotations.
json
{"VariantTypeAnnotation": {"prefix": ["variant-type", "vt"],"body": ["export type $1<T extends TypeNames<typeof $1> = undefined> = VariantOf<typeof $1, T>;",],"description": "Type annotation for variants"},"VariantSimpleTypeAnnotation": {"prefix": ["variant-simple-type", "vst"],"body": ["export type $1 = VariantOf<typeof $1>;",],"description": "Type annotation for generic variants"},"VariantGenericTypeAnnotation": {"prefix": ["variant-generic-type", "vgt"],"body": ["export type $1<T, TType extends TypeNames<typeof $1> = undefined> = GVariantOf<typeof $1, TType, {T: T}>;",],"description": "Type annotation for generic variants"},}
json
{"VariantTypeAnnotation": {"prefix": ["variant-type", "vt"],"body": ["export type $1<T extends TypeNames<typeof $1> = undefined> = VariantOf<typeof $1, T>;",],"description": "Type annotation for variants"},"VariantSimpleTypeAnnotation": {"prefix": ["variant-simple-type", "vst"],"body": ["export type $1 = VariantOf<typeof $1>;",],"description": "Type annotation for generic variants"},"VariantGenericTypeAnnotation": {"prefix": ["variant-generic-type", "vgt"],"body": ["export type $1<T, TType extends TypeNames<typeof $1> = undefined> = GVariantOf<typeof $1, TType, {T: T}>;",],"description": "Type annotation for generic variants"},}