my DMs. • I’m on y’all’s Slack under @steve. • I’m on Twitter—under duress—under @stevekinney. • All of this content today can be found here: https:// stevekinney.github.io/react-and-typescript/
at compile time is way better than things crashing or—worse—behaving unexpectedly at run time. • You get a better development experience because autocomplete knows more about what you’re intending on doing. • Large codebases stay more maintainable because you’re able to put guardrails on how your code can be used.
placeholder. anotherObject: {}; // Can have any properties and values. item: { id: string; title: string; }; items: { id: string; title: string; }[]; // An array of objects of a certain shape. };
Does not return anything. onHover: () => void; // Takes a number. Returns nothing (e.g. undefined). onChange: (id: number) => void; // Takes an event that is based on clicking on a button. // Returns nothing. onClick(event: React.MouseEvent<HTMLButtonElement>): void; };
type IsAssignableTo<A, B> = A extends B ? true : false; // Type `123` is assignable to type `number` // Inferred Type: true type Result1 = IsAssignableTo<123, number>; // Type `number` is not assignable to type `123` // Inferred Type: false type Result2 = IsAssignableTo<number, 123>;
UppercaseWes = Uppercase<"wes">; type LowercaseWes = Lowercase<"Wes">; type CapitalizeWes = Capitalize<"wes">; type UncapitalizeWes = Uncapitalize<"Wes">;