随笔分类 -  TypeScript

上一页 1 ··· 9 10 11 12 13 14 15 16 17 ··· 30 下一页
摘要:You can use `extends infer X` to assign the result of an expression to a variable type SomeFunction<U> = SuperHeavyComputation<U> extends infer Result 阅读全文
posted @ 2022-11-17 15:11 Zhentiw 阅读(13) 评论(0) 推荐(0)
摘要:The enum is an original syntax of TypeScript (it does not exist in JavaScript). So it is converted to like the following form as a result of transpila 阅读全文
posted @ 2022-11-16 22:35 Zhentiw 阅读(30) 评论(0) 推荐(0)
摘要:Similar to Array.findIndex: type FindIndex<T extends readonly any[], K, ACC extends unknown[] = []> = T extends readonly [infer F, ...infer RT] ? K ex 阅读全文
posted @ 2022-11-16 22:34 Zhentiw 阅读(44) 评论(0) 推荐(0)
摘要:type OnPropChangedMethods<T> = { [Key in keyof T & string as `${Key}Changed`]: (cb: (newValue: T[Key]) => void) => void } declare function makeWatched 阅读全文
posted @ 2022-11-16 15:02 Zhentiw 阅读(16) 评论(0) 推荐(0)
摘要:type Placeholder<T extends string> = T extends `${string}{${infer P}}${infer REST}` ? P | Placeholder<REST> : never; declare function format<S extends 阅读全文
posted @ 2022-11-16 14:48 Zhentiw 阅读(27) 评论(0) 推荐(0)
摘要:Implement a type FilterOut<T, F> that filters out items of the given type F from the tuple T. For example, type Filtered = FilterOut<[1, 2, null, 3], 阅读全文
posted @ 2022-11-16 02:19 Zhentiw 阅读(19) 评论(0) 推荐(0)
摘要:Convert a string literal to a number, which behaves like Number.parseInt. /* _____________ Your Code Here _____________ */ type ToNumber<S extends str 阅读全文
posted @ 2022-11-15 00:43 Zhentiw 阅读(19) 评论(0) 推荐(0)
摘要:The get function in lodash is a quite convenient helper for accessing nested values in JavaScript. However, when we come to TypeScript, using function 阅读全文
posted @ 2022-11-15 00:34 Zhentiw 阅读(20) 评论(0) 推荐(0)
摘要:Sometimes it's useful to detect if you have a value with any type. This is especially helpful while working with third-party Typescript modules, which 阅读全文
posted @ 2022-11-14 01:01 Zhentiw 阅读(52) 评论(0) 推荐(0)
摘要:Implement CamelCase<T> which converts snake_case string to camelCase. For example type camelCase1 = CamelCase<'hello_world_with_types'> // expected to 阅读全文
posted @ 2022-11-12 17:28 Zhentiw 阅读(25) 评论(0) 推荐(0)
摘要:Implement a type that adds a new field to the interface. The type takes the three arguments. The output should be an object with the new field. For ex 阅读全文
posted @ 2022-11-12 17:02 Zhentiw 阅读(17) 评论(0) 推荐(0)
摘要:import { z } from "zod"; export enum SUBTYPE { ABORT = "abort", START = "start", UPLOAD = "upload", LOADING = "loading", } export const TYPE = "print" 阅读全文
posted @ 2022-11-11 20:42 Zhentiw 阅读(35) 评论(0) 推荐(0)
摘要:Implement CapitalizeWords<T> which converts the first letter of each word of a string to uppercase and leaves the rest as-is. For example type capital 阅读全文
posted @ 2022-11-11 15:51 Zhentiw 阅读(30) 评论(0) 推荐(0)
摘要:Implement the advanced util type OptionalKeys<T>, which picks all the optional keys into a union. /* _____________ Your Code Here _____________ */ typ 阅读全文
posted @ 2022-11-11 00:11 Zhentiw 阅读(22) 评论(0) 推荐(0)
摘要:Implement the advanced util type RequiredKeys<T>, which picks all the required keys into a union. For example type Result = RequiredKeys<{ foo: number 阅读全文
posted @ 2022-11-11 00:07 Zhentiw 阅读(42) 评论(0) 推荐(0)
摘要:Implement the advanced util type GetOptional<T>, which remains all the optional fields For example type I = GetOptional<{ foo: number, bar?: string }> 阅读全文
posted @ 2022-11-10 22:03 Zhentiw 阅读(25) 评论(0) 推荐(0)
摘要:Implement the advanced util type GetRequired<T>, which remains all the required fields For example type I = GetRequired<{ foo: number, bar?: string }> 阅读全文
posted @ 2022-11-10 21:57 Zhentiw 阅读(36) 评论(0) 推荐(0)
摘要:type PathParams<S extends string> = S extends `/${string}/:${infer Param}/${infer REST}` ? Param | PathParams<`/${REST}`> : S extends `${string}/:${in 阅读全文
posted @ 2022-11-09 22:28 Zhentiw 阅读(16) 评论(0) 推荐(0)
摘要:Implement the advanced util type UnionToIntersection<U> For example type I = Union2Intersection<'foo' | 42 | true> // expected to be 'foo' & 42 & true 阅读全文
posted @ 2022-11-09 17:22 Zhentiw 阅读(42) 评论(0) 推荐(0)
摘要:So what is a nake type? Example: type UnionToIntersection<T> = (T extends any ? (x: T) => any : never) //... We check Tin a sub-type condition, T exte 阅读全文
posted @ 2022-11-09 02:47 Zhentiw 阅读(23) 评论(0) 推荐(0)

上一页 1 ··· 9 10 11 12 13 14 15 16 17 ··· 30 下一页