Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
まだまだTypeScript

まだまだTypeScript

Recordを使って型を一括変換

type Obj = {
    name: string
    age: number
}

type ObjString = Record<keyof Obj, string | null>

const a: ObjString = { name: "kenji", age: 88 }

// Type 'number' is not assignable to type 'string | null'.

neverは返らない

  • mapped type, `T[keyof T]
type T = {
    name: string
    age: number
    job: never
}
type Type2 = T[keyof T]
//Type2 is  "string" | "number"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment