diff --git a/pages/src/pages/legend/type_categories.md b/pages/src/pages/legend/type_categories.md deleted file mode 100644 index bbe416ec1..000000000 --- a/pages/src/pages/legend/type_categories.md +++ /dev/null @@ -1,84 +0,0 @@ -# Type Categories - -## βš—οΈ Transformation - -Transformation type (βš—οΈ alembic) transforms the input type from one set to another. - -Technically, any type with type parameter are transformation type. -So that definition is not that helpful in our context. - -Instead, we will use transformation type to describe the types that transform the input to a different form within the same category. - -## 🧱 Building Types - -Building type (🧱 bricks) is a type that can be used to build other types. - -(other icons considered: 🧰 toolbox, πŸ› οΈ hammer_and_wrench) - -## πŸ’€ Deprecated - -Deprecated type (πŸ’€ deprecated) is a type that is deprecated and will be removed soon. - -## πŸ›‘οΈ Type Guard - -Type guard (πŸ›‘οΈ guard) is a specific type of predicate function in TypeScript that can narrow the type of the input parameter to its subtype. -The return value of a type guard function is a [type predicate]. - -## 🚦 Assertion Functions - -[Assertion function] (🚦 vertical_traffic_light) is a specific kind of function that narrows the input type using the `asserts condition` syntax. - -They act like NodeJS's `assert()` function. The function is used as a statement. -If the assertion fails, it throws an exception. Otherwise, TypeScript knows the `asserts condition` is met, -and the input type is narrowed according to the condition in the remaining of the scope. - -## πŸ§ͺ Testing - -Testing types or functions (πŸ§ͺ test_tube) are designed for testing. - -## πŸŒͺ️ Filter - -Filter (πŸŒͺ️ tornado) is a type or function that filters the input. -If the input passes the filter, it is returned unchanged. Otherwise, it returns `never`. - -Filter is also known as *pares*, as in [Parse, don't validate]. - -The returned input can be narrowed if [πŸ”€ distributive] is enabled (on by default). - -This means it is better to infer the return type instead of reusing the input type: - -```ts -type IsUndefined = T extends undefined ? T : never - -// yes, these are silly, but just an example -type Bad = IsUndefined extends T ? T : never -type Good = IsUndefined extends infer R ? R : never - -type R1 = Bad // undefined | number -type R2 = Good // undefined -``` - -(other icons considered: β†ͺοΈπŸ‘‰πŸš‹β©πŸΎπŸ”‘πŸšͺπŸ’‚πŸ§²πŸ™…β€β™‚οΈπŸͺš) - -## 🎭 Predicate - -Predicate (🎭 performing_arts) is also known as *validate* or *logical*. -If the input satisfies the predicate, it returns `true`. Otherwise, `false`. - -(other icons considered: β­•) - -## πŸƒ Runtime - -Runtime (πŸƒ runner) means the utility (e.g. a function) has runtime effect. - -## Others - -- πŸ‘½ *alias* (:alien:): Alias of another type -- πŸ’₯ *immediate* (:boom:): The effect of the type can be observed immediately during development -- 🩳 *shortcut* (:shorts:): Shortcut or convenient types -- 🦴 *utilities* (:bone:): provide various functionalities (other icons considered: πŸ”§πŸ”¨) - -[type predicate]: https://www.typescriptlang.org/docs/handbook/2/narrowing.html#using-type-predicates -[Assertion function]: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#assertion-functions -[Parse, don't validate]: https://lexi-lambda.github.io/blog/2019/11/05/parse-don-t-validate/ -[πŸ”€ distributive]: ./type_options.md#πŸ”€-distributive diff --git a/pages/src/pages/legend/type_options.md b/pages/src/pages/legend/type_options.md deleted file mode 100644 index 8b4687801..000000000 --- a/pages/src/pages/legend/type_options.md +++ /dev/null @@ -1,20 +0,0 @@ -# Type Options - -These are typical options available ti the types and what do they mean. - -## πŸ”€ Distributive - -Distributive (πŸ”€ twisted_rightwards_arrows) means each value in a union type will be evaluated separately in conditional types, -so both branches may be executed. - -```ts -type R = IsUndefined // true | false -> boolean -``` - -## πŸ“Œ Exact - -Exact (πŸ“Œ pushpin) means type comparison will be performed strictly, treating subtype as separate types. - -```ts -type R1 = IsString<'a', { exact: true }> // false -```