Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
| note:tue_jun_17_2025 [2025/06/17 08:37] – root1 | note:tue_jun_17_2025 [2025/06/17 13:00] (current) – [dokuwiki docker upgrade] lingao | ||
|---|---|---|---|
| Line 3: | Line 3: | ||
| typehero | typehero | ||
| - | <codeprism | + | <code ts> |
| declare const config: Chainable | declare const config: Chainable | ||
| Line 20: | Line 20: | ||
| } | } | ||
| } | } | ||
| - | </codeprism> | + | </code> |
| ===== Type Argument Inference in TypeScript ===== | ===== Type Argument Inference in TypeScript ===== | ||
| Line 27: | Line 27: | ||
| - | <codeprism | + | <code typescript> |
| type Chainable< | type Chainable< | ||
| option<K extends string, V>(key: Exclude< | option<K extends string, V>(key: Exclude< | ||
| get(): T | get(): T | ||
| } | } | ||
| - | </codeprism> | + | </code> |
| Why K is Inferred, Not T? | Why K is Inferred, Not T? | ||
| TypeScript' | TypeScript' | ||
| - | <codeprism | + | <code typescript> |
| // When you write: | // When you write: | ||
| config.option(' | config.option(' | ||
| Line 47: | Line 47: | ||
| // - Second argument: ' | // - Second argument: ' | ||
| // → Must infer V = ' | // → Must infer V = ' | ||
| - | </codeprism> | + | </code> |
| What If T Were Also a Type Parameter? | What If T Were Also a Type Parameter? | ||
| If we hypothetically made T also inferrable, it would create ambiguity: | If we hypothetically made T also inferrable, it would create ambiguity: | ||
| - | <codeprism | + | <code typescript> |
| // Hypothetical (problematic) design: | // Hypothetical (problematic) design: | ||
| type BadChainable = { | type BadChainable = { | ||
| Line 63: | Line 63: | ||
| // How would TypeScript know what T should be? | // How would TypeScript know what T should be? | ||
| // There would be no way to infer T from the arguments! | // There would be no way to infer T from the arguments! | ||
| - | </codeprism> | + | </code> |
| ===== The NoInfer Utility Type ===== | ===== The NoInfer Utility Type ===== | ||
| - | <codeprism | + | <code lang=typescript el=true > |
| function createStreetLight< | function createStreetLight< | ||
| // ... | // ... | ||
| Line 85: | Line 85: | ||
| // Argument of type '" | // Argument of type '" | ||
| - | </codeprism> | + | </code> |
| ===== dokuwiki docker upgrade ===== | ===== dokuwiki docker upgrade ===== | ||
| - | <codeprism | + | <code lang=bash> |
| tar -czvf " | tar -czvf " | ||
| mv *config.tar.gz ./backup | mv *config.tar.gz ./backup | ||
| docker compose down && docker compose pull && docker compose up -d | docker compose down && docker compose pull && docker compose up -d | ||
| - | </codeprism> | + | </code> |
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| + | ===== Tuple Map ===== | ||
| + | we can use mapped types for creating tuples. It's because tuple properties are indexes. | ||
| + | <code typescript> | ||
| + | type A<T extends unknown[]> | ||
| + | [P in keyof T] : T[P] | ||
| + | } | ||
| + | type a = A< | ||
| + | // ^ type a = [1, 2, 3] | ||
| + | </ | ||