blog
blog copied to clipboard
使用Typescript的用法备忘
- Record 可以保证映射完整:
export enum EnvironmentType {
development = "development",
staging = "staging",
production = "production"
}
export interface EnvironmentConfig {
server: string
port: number
}
type EnvironmentConfigMap = Record<EnvironmentType, EnvironmentConfig>
- 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