Last active
March 25, 2023 15:42
-
-
Save mattywong/ae87965c936eabe622d45d315e0c9f5a to your computer and use it in GitHub Desktop.
Typescript snippets #snippets #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
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]; | |
}; |
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
// 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; | |
} |
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
// 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