Skip to content

Instantly share code, notes, and snippets.

@mattywong
Last active March 25, 2023 15:42
Show Gist options
  • Save mattywong/ae87965c936eabe622d45d315e0c9f5a to your computer and use it in GitHub Desktop.
Save mattywong/ae87965c936eabe622d45d315e0c9f5a to your computer and use it in GitHub Desktop.
Typescript snippets #snippets #typescript
interface AppState {
gender: Gender | null;
age: number | null;
height: number | null;
weight: number | null;
shouldSendResult: boolean;
currentStep: number;
}
interface AppStateProvider {
initialState: {
[key in keyof AppState]?: AppState[key];
};
// https://github.com/microsoft/TypeScript/issues/13042#issuecomment-393653843
enum Test {
A = "a",
B = "b"
}
type SomeType = {
[x in Test]: () => void;
};
// Below does not work with interface, only type
interface SomeInterface {
[x in Test]: () => void;
}
// Keyof Generic interface
interface FormContext<Values = {}> {
values: Values;
touched: {
[Key in keyof Values]: boolean;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment