Many of the more "advanced" typescript features can be used for creating "value-derived" types.
At its simplest form:
let vehicle = { name: "Van", wheels: 4 }| var list = []; | |
| document.querySelectorAll("body *") | |
| .forEach(function(elem){ | |
| if(elem.getBoundingClientRect().width > document.body.getBoundingClientRect().width){ | |
| list.push(elem.outerHTML.split('>')[0] + '>'); | |
| } | |
| }); | |
| confirm( "these elements are wider than the viewport:\n\n " + list.join("\n") ) |
| import { OperatorFunction } from 'ix/interfaces'; | |
| import { pipe } from 'ix/iterable'; | |
| import { map } from 'ix/iterable/operators'; | |
| /** | |
| * Creates a new type which is the first element of a non-empty tuple type. | |
| * | |
| * @example type T = Head<[string, number, Object]>; // string | |
| */ | |
| export type Head<Ts extends [any, ...any[]]> = Ts extends [infer T, ...any[]] ? T : never; |
| type SomeProps = | |
| | { action: "START" } | |
| | { action: "STOP"; time: number } | |
| | { action: "PAUSE"; time: number; ref: { current: any } }; | |
| function useExample(props: SomeProps) { | |
| let { | |
| action, // "START" | "STOP" | "PAUSE" | |
| time, // number | undefined, | |
| ref // { current: any } | undefined |