note:tue_jun_17_2025

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
note:tue_jun_17_2025 [2025/06/17 08:37] root1note:tue_jun_17_2025 [2025/06/17 13:00] (current) – [dokuwiki docker upgrade] lingao
Line 3: Line 3:
 typehero typehero
  
-<codeprism ts>+<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 typescript>+<code typescript>
 type Chainable<T = {}> = { type Chainable<T = {}> = {
   option<K extends string, V>(key: Exclude<K, keyof T>, value: V): Chainable<Omit<T, K> & {[P in K]: V}>   option<K extends string, V>(key: Exclude<K, keyof T>, value: V): Chainable<Omit<T, K> & {[P in K]: V}>
   get(): T   get(): T
 } }
-</codeprism>+</code>
  
 Why K is Inferred, Not T? Why K is Inferred, Not T?
  
 TypeScript's inference flows from unknown type parameters based on known argument types: TypeScript's inference flows from unknown type parameters based on known argument types:
-<codeprism typescript>+<code typescript>
 // When you write: // When you write:
 config.option('database', 'mysql') config.option('database', 'mysql')
Line 47: Line 47:
 // - Second argument: 'mysql' (literal string)   // - Second argument: 'mysql' (literal string)  
 //   → Must infer V = 'mysql' (UNKNOWN → INFERRED) //   → Must infer V = 'mysql' (UNKNOWN → INFERRED)
-</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 typescript>+<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 lang=typescript el=true >+<code lang=typescript el=true >
 function createStreetLight<C extends string>(colors: C[], defaultColor?: C) { function createStreetLight<C extends string>(colors: C[], defaultColor?: C) {
     // ...     // ...
Line 85: Line 85:
 // Argument of type '"blue"' is not assignable to parameter of type '"red" | "yellow" | "green" | undefined'. // Argument of type '"blue"' is not assignable to parameter of type '"red" | "yellow" | "green" | undefined'.
  
-</codeprism>+</code>
  
 ===== dokuwiki docker upgrade ===== ===== dokuwiki docker upgrade =====
  
-<codeprism lang=bash>+<code lang=bash>
 tar -czvf "$(date +'%Y-%m-%d_%H-%M-%S')_config.tar.gz" ./config  tar -czvf "$(date +'%Y-%m-%d_%H-%M-%S')_config.tar.gz" ./config 
 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<[1,2,3]>
 +//   ^ type a = [1, 2, 3]
 +</code>
  • note/tue_jun_17_2025.1750149456.txt.gz
  • Last modified: 2025/06/17 08:37
  • by root1