上一页 1 ··· 85 86 87 88 89 90 91 92 93 ··· 469 下一页
摘要: Implement a generic First<T> that takes an Array T and returns it's first element's type. type arr1 = ['a', 'b', 'c'] type arr2 = [3, 2, 1] type head1 阅读全文
posted @ 2022-09-02 01:30 Zhentiw 阅读(18) 评论(0) 推荐(0) 编辑
摘要: If you cannot catch those pesky errors for any reason. Maybe some lib is throwing them and you can't catch them. You can use: process.on('uncaughtExce 阅读全文
posted @ 2022-09-02 01:26 Zhentiw 阅读(10) 评论(0) 推荐(0) 编辑
摘要: For example: const tuple = ['tesla', 'model 3', 'model X', 'model Y'] as const type result = TupleToObject<typeof tuple> // expected { tesla: 'tesla', 阅读全文
posted @ 2022-08-31 15:51 Zhentiw 阅读(29) 评论(0) 推荐(0) 编辑
摘要: For example: interface Todo { title: string description: string } const todo: MyReadonly<Todo> = { title: "Hey", description: "foobar" } todo.title = 阅读全文
posted @ 2022-08-31 15:26 Zhentiw 阅读(26) 评论(0) 推荐(0) 编辑
摘要: For example: interface Todo { title: string description: string completed: boolean } type TodoPreview = MyPick<Todo, 'title' | 'completed'> const todo 阅读全文
posted @ 2022-08-31 15:23 Zhentiw 阅读(32) 评论(0) 推荐(0) 编辑
摘要: Reuse existing instances when working with identical objects The flyweight pattern is useful when you're creating a huge number of objects, which coul 阅读全文
posted @ 2022-08-31 14:59 Zhentiw 阅读(15) 评论(0) 推荐(0) 编辑
摘要: You're given an array of integers and another array of three distinct integers. The first array is guaranteed to only contain integers that are in the 阅读全文
posted @ 2022-08-30 20:55 Zhentiw 阅读(17) 评论(0) 推荐(0) 编辑
摘要: Step 7: Tests for Types The assertion type code need to be tested just as the normal code. export function isITeam(arg: any): arg is ITeam { /** * { i 阅读全文
posted @ 2022-08-30 18:09 Zhentiw 阅读(34) 评论(0) 推荐(0) 编辑
摘要: Step1 & 2 for converting a js app to ts Step 3. Turn on "noImplicitAny" and even more strict mode Step 4. ESLint for Typescript Step5. Local types ove 阅读全文
posted @ 2022-08-30 18:09 Zhentiw 阅读(19) 评论(0) 推荐(0) 编辑
摘要: Step 5: Types at Runtime This problem often happens when APi return the data. let cachedAllTeamsList: Promise<ITeam[]>; export async function getAllTe 阅读全文
posted @ 2022-08-30 15:32 Zhentiw 阅读(21) 评论(0) 推荐(0) 编辑
上一页 1 ··· 85 86 87 88 89 90 91 92 93 ··· 469 下一页