随笔分类 -  TypeScript

上一页 1 ··· 12 13 14 15 16 17 18 19 20 ··· 30 下一页
摘要:The Block, Element, Modifier methodology (BEM) is a popular naming convention for classes in CSS. For example, the block component would be represente 阅读全文
posted @ 2022-10-20 18:29 Zhentiw 阅读(19) 评论(0) 推荐(0)
摘要:If you're thinking about putting a TypeScript package up to NPM, you should be considering preconstruct. It makes setup EXTREMELY easy and takes many 阅读全文
posted @ 2022-10-20 14:31 Zhentiw 阅读(21) 评论(0) 推荐(0)
摘要:You can DRY up your generics code MASSIVELY (and improve perf) by assigning local variables to default generic slots. Here, we move some complex 'Extr 阅读全文
posted @ 2022-10-20 14:21 Zhentiw 阅读(21) 评论(0) 推荐(0)
摘要:You can use generics to dynamically specify the number, and type, of arguments to functions. Here, we create a sendEvent function which only asks for 阅读全文
posted @ 2022-10-20 03:09 Zhentiw 阅读(38) 评论(0) 推荐(0)
摘要:Recursively flatten array up to depth times. For example: type a = FlattenDepth<[1, 2, [3, 4], [[[5]]]], 2> // [1, 2, 3, 4, [5]]. flattern 2 times typ 阅读全文
posted @ 2022-10-19 14:54 Zhentiw 阅读(23) 评论(0) 推荐(0)
摘要:Accessing object values and array members is MUCH more powerful in the type world than it is in the runtime world. Passing a union... RETURNS a union! 阅读全文
posted @ 2022-10-18 20:53 Zhentiw 阅读(23) 评论(0) 推荐(0)
摘要:Implement the type version of lodash's _.flip. Type FlipArguments<T> requires function type T and returns a new function type which has the same retur 阅读全文
posted @ 2022-10-18 19:22 Zhentiw 阅读(27) 评论(0) 推荐(0)
摘要:Implement the type version of Array.reverse For example: type a = Reverse<['a', 'b']> // ['b', 'a'] type b = Reverse<['a', 'b', 'c']> // ['c', 'b', 'a 阅读全文
posted @ 2022-10-18 19:12 Zhentiw 阅读(8) 评论(0) 推荐(0)
摘要:This one little tip has saved me hours of refactoring time. Passing string | undefined instead of ?: string ensures that ALL call sites must be given 阅读全文
posted @ 2022-10-18 01:39 Zhentiw 阅读(21) 评论(0) 推荐(0)
摘要:The "noUncheckedIndexedAccess" is the most awesome config option you've never heard of. It makes accessing objects a lot safer, and also powers up Typ 阅读全文
posted @ 2022-10-18 01:33 Zhentiw 阅读(31) 评论(0) 推荐(0)
摘要:Mapping over a union type can feel tricky to conceptualise. But actually, TypeScript does it all for you - using Distributive Conditional Types. Here, 阅读全文
posted @ 2022-10-18 01:22 Zhentiw 阅读(32) 评论(0) 推荐(0)
摘要:Globals in TypeScript?! 🤯 declare global is a super useful tool for when you want to allow types to cross module boundaries. Here, we create a Global 阅读全文
posted @ 2022-10-18 01:18 Zhentiw 阅读(149) 评论(0) 推荐(0)
摘要:Given a tuple type T that only contains string type, and a type U, build an object recursively. type a = TupleToNestedObject<['a'], string> // {a: str 阅读全文
posted @ 2022-10-17 14:53 Zhentiw 阅读(28) 评论(0) 推荐(0)
摘要:Implement the type version of Array.shift For example type Result = Shift<[3, 2, 1]> // [2, 1] /* _____________ Your Code Here _____________ */ type S 阅读全文
posted @ 2022-10-17 14:41 Zhentiw 阅读(21) 评论(0) 推荐(0)
摘要:Implement the type version of Object.entries For example interface Model { name: string; age: number; locations: string[] | null; } type modelEntries 阅读全文
posted @ 2022-10-16 17:08 Zhentiw 阅读(19) 评论(0) 推荐(0)
摘要:Implement the generic Mutable<T> which makes all properties in T mutable (not readonly). For example interface Todo { readonly title: string readonly 阅读全文
posted @ 2022-10-15 20:36 Zhentiw 阅读(20) 评论(0) 推荐(0)
摘要:Want to turn a module into a type? You can use typeof import('./') to grab the type of any module, even third-party ones. Here, we create a type from 阅读全文
posted @ 2022-10-15 20:27 Zhentiw 阅读(24) 评论(0) 推荐(0)
摘要:Implement a generic RequiredByKeys<T, K> which takes two type argument T and K. K specify the set of properties of T that should set to be required. W 阅读全文
posted @ 2022-10-14 19:14 Zhentiw 阅读(19) 评论(0) 推荐(0)
摘要:Implement a generic PartialByKeys<T, K> which takes two type argument T and K. K specify the set of properties of T that should set to be optional. Wh 阅读全文
posted @ 2022-10-14 19:04 Zhentiw 阅读(27) 评论(0) 推荐(0)
摘要:Implement EndsWith<T, U> which takes two exact string types and returns whether T ends with U For example: type a = EndsWith<'abc', 'bc'> // expected 阅读全文
posted @ 2022-10-14 01:40 Zhentiw 阅读(26) 评论(0) 推荐(0)

上一页 1 ··· 12 13 14 15 16 17 18 19 20 ··· 30 下一页