随笔分类 -  TypeScript

上一页 1 ··· 7 8 9 10 11 12 13 14 15 ··· 30 下一页
摘要: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 阅读(29) 评论(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 阅读(34) 评论(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 阅读(23) 评论(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 阅读(18) 评论(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 阅读(54) 评论(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 阅读(29) 评论(0) 推荐(0)
摘要:Implement the type Filter<T, Predicate> takes an Array T, primitive type or union primitive type Predicate and returns an Array include the elements o 阅读全文
posted @ 2022-12-11 17:26 Zhentiw 阅读(16) 评论(0) 推荐(0)
摘要:Returns true if all elements of the list are equal to the second parameter passed in, false if there are any mismatches. For example type Test1 = [1, 阅读全文
posted @ 2022-12-11 00:03 Zhentiw 阅读(18) 评论(0) 推荐(0)
摘要:You're required to implement a type-level parser to parse URL query string into a object literal type. Some detailed requirements: Value of a key in q 阅读全文
posted @ 2022-12-08 22:21 Zhentiw 阅读(31) 评论(0) 推荐(0)
摘要:Given an union of types and array of type pairs to replace ([[string, number], [Date, null]]), return a new union replaced with the type pairs. /* ___ 阅读全文
posted @ 2022-12-07 20:12 Zhentiw 阅读(21) 评论(0) 推荐(0)
摘要:Capitalize the key of the object, and if the value is an array, iterate through the objects in the array. /* _____________ Your Code Here ____________ 阅读全文
posted @ 2022-12-06 21:24 Zhentiw 阅读(24) 评论(0) 推荐(0)
摘要:You have a target object and a source array of objects. You need to copy property from source to target, if it has the same property as the source, yo 阅读全文
posted @ 2022-12-05 14:51 Zhentiw 阅读(23) 评论(0) 推荐(0)
摘要:Given an array of integers nums and an integer target, return true if two numbers such that they add up to target. /* _____________ Your Code Here ___ 阅读全文
posted @ 2022-12-04 22:29 Zhentiw 阅读(18) 评论(0) 推荐(0)
摘要:Get all possible paths that could be called by _.get (a lodash function) to get the value of an object type T1 = ObjectKeyPaths<{ name: string; age: n 阅读全文
posted @ 2022-12-03 20:40 Zhentiw 阅读(23) 评论(0) 推荐(0)
摘要:Implement BinaryToDecimal<S> which takes an exact string type S consisting 0 and 1 and returns an exact number type corresponding with S when S is reg 阅读全文
posted @ 2022-12-02 21:41 Zhentiw 阅读(32) 评论(0) 推荐(0)
摘要:Implement the type version of Lodash.intersection with a little difference. Intersection takes an Array T containing several arrays or any type elemen 阅读全文
posted @ 2022-12-01 16:26 Zhentiw 阅读(20) 评论(0) 推荐(0)
摘要:type RGB = [number, number, number] const palette: Record<'red' | 'blue' | 'green', string | RGB> = { red: [255, 0, 0], green: "#00ff00", blue: [0,0,2 阅读全文
posted @ 2022-11-30 15:53 Zhentiw 阅读(20) 评论(0) 推荐(0)
摘要:Typescript 4.9 supports an upcoming feature: Auto-accessors: class Person { accessor name: string constructor(name: string) { this.name = name } } Und 阅读全文
posted @ 2022-11-30 15:24 Zhentiw 阅读(53) 评论(0) 推荐(0)
摘要:Before version 4.9, you will get type error for the code: interface Context { packageJSON: unknown } function tryGetPackageName(context: Context) { co 阅读全文
posted @ 2022-11-30 15:15 Zhentiw 阅读(28) 评论(0) 推荐(0)
摘要:Implement the advanced util type MutableKeys, which picks all the mutable (not readonly) keys into a union. For example: type Keys = MutableKeys<{ rea 阅读全文
posted @ 2022-11-30 14:48 Zhentiw 阅读(31) 评论(0) 推荐(0)

上一页 1 ··· 7 8 9 10 11 12 13 14 15 ··· 30 下一页