blog icon indicating copy to clipboard operation
blog copied to clipboard

使用Typescript的用法备忘

Open waltcow opened this issue 5 years ago • 0 comments

  1. Record 可以保证映射完整:
export enum EnvironmentType {
    development = "development",
    staging = "staging",
    production = "production"
}

export interface EnvironmentConfig {
    server: string
    port: number
}

type EnvironmentConfigMap = Record<EnvironmentType, EnvironmentConfig>

  1. infer
type FlattenIfArray<T> = T extends (infer R)[] ? R : T

Check if our generic Type is the array, If it is array extract the real type from it, If it does not leave it as is

waltcow avatar Jul 31 '19 02:07 waltcow