-
-
Save stevekinney/2063a12c3bc76645f22e54e7d079ec39 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
type AppProps = { | |
message: string; | |
count: number; | |
disabled: boolean; | |
/** array of a type! */ | |
names: string[]; | |
/** string literals to specify exact string values, with a union type to join them together */ | |
status: "waiting" | "success"; | |
/** any object as long as you dont use its properties (NOT COMMON but useful as placeholder) */ | |
obj: object; | |
obj2: {}; // almost the same as `object`, exactly the same as `Object` | |
/** an object with any number of properties (PREFERRED) */ | |
obj3: { | |
id: string; | |
title: string; | |
}; | |
/** array of objects! (common) */ | |
objArr: { | |
id: string; | |
title: string; | |
}[]; | |
/** a dict object with any number of properties of the same type */ | |
dict1: { | |
[key: string]: MyTypeHere; | |
}; | |
dict2: Record<string, MyTypeHere>; // equivalent to dict1 | |
/** any function as long as you don't invoke it (not recommended) */ | |
onSomething: Function; | |
/** function that doesn't take or return anything (VERY COMMON) */ | |
onClick: () => void; | |
/** function with named prop (VERY COMMON) */ | |
onChange: (id: number) => void; | |
/** alternative function type syntax that takes an event (VERY COMMON) */ | |
onClick(event: React.MouseEvent<HTMLButtonElement>): void; | |
/** an optional prop (VERY COMMON!) */ | |
optional?: OptionalType; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment