上一页 1 ··· 57 58 59 60 61 62 63 64 65 ··· 467 下一页
摘要: type NonEmptyArray<T> = [T, ...Array<T>]; export const makeEnum = (values: NonEmptyArray<string>) => {}; makeEnum(["a"]); makeEnum(["a", "b", "c"]); / 阅读全文
posted @ 2022-12-11 22:16 Zhentiw 阅读(9) 评论(0) 推荐(0) 编辑
摘要: export type Maybe<T extends {}> = T | null | undefined; type tests = [ // @ts-expect-error Maybe<null>, // @ts-expect-error Maybe<undefined>, Maybe<st 阅读全文
posted @ 2022-12-11 22:11 Zhentiw 阅读(17) 评论(0) 推荐(0) 编辑
摘要: import { Equal, Expect } from "../helpers/type-utils"; type Maybe<T> = T | null | undefined; type tests = [ Expect<Equal<Maybe<string>, string | null 阅读全文
posted @ 2022-12-11 22:03 Zhentiw 阅读(10) 评论(0) 推荐(0) 编辑
摘要: import { Equal, Expect } from "../helpers/type-utils"; type Identity<T> = T; type tests = [ Expect<Equal<Identity<1>, 1>>, Expect<Equal<Identity<"1">, 阅读全文
posted @ 2022-12-11 22:01 Zhentiw 阅读(23) 评论(0) 推荐(0) 编辑
摘要: Let's say we have type TemplateLiteralKey = `${"user" | "post" | "comment"}${"Id" | "Name"}`; We want to make a type type ObjectOfKeys = unknown; In o 阅读全文
posted @ 2022-12-11 21:57 Zhentiw 阅读(25) 评论(0) 推荐(0) 编辑
摘要: Here we have a Sandwich type that's currently assigned to unknown We also have a couple of union types, BreadType and Filling, that have several optio 阅读全文
posted @ 2022-12-11 21:46 Zhentiw 阅读(24) 评论(0) 推荐(0) 编辑
摘要: Let's say we have an object as const: const frontendToBackendEnumMap = { singleModule: "SINGLE_MODULE", multiModule: "MULTI_MODULE", sharedModule: "SH 阅读全文
posted @ 2022-12-11 20:37 Zhentiw 阅读(17) 评论(0) 推荐(0) 编辑
摘要: Let's say we have a const of object: export const programModeEnumMap = { GROUP: "group", ANNOUNCEMENT: "announcement", ONE_ON_ONE: "1on1", SELF_DIRECT 阅读全文
posted @ 2022-12-11 20:35 Zhentiw 阅读(14) 评论(0) 推荐(0) 编辑
摘要: For example we have a discriminated union type: export type Event = | { type: "click"; event: MouseEvent; } | { type: "focus"; event: FocusEvent; } | 阅读全文
posted @ 2022-12-11 20:18 Zhentiw 阅读(47) 评论(0) 推荐(0) 编辑
摘要: Give a discriminated union: export type Event = | { type: "click"; event: MouseEvent; } | { type: "focus"; event: FocusEvent; } | { type: "keydown"; e 阅读全文
posted @ 2022-12-11 20:11 Zhentiw 阅读(24) 评论(0) 推荐(0) 编辑
上一页 1 ··· 57 58 59 60 61 62 63 64 65 ··· 467 下一页