2021-08-11 typescript 学习笔记

2021-08-11  本文已影响0人  rub1cky

keyof

keyof用于获取对象的key

type Point = {
  x: number;
  y: number;
}

type KPoint = keyof Point; // x | y

typeof


const point = {
a : 1,
b: 'test'
}
type P = keyof typeof point; // type '"a" || "b"'

const coordinate: P = 'z' // Type '"z"' is not assignable to type '"a" | "b"'.
上一篇 下一篇

猜你喜欢

热点阅读