随笔分类 -  TypeScript

上一页 1 2 3 4 5 6 7 8 ··· 30 下一页
摘要:// Before declare function createFSM<TState extends string>(config: { // Without NoInfer, TS doesn't know which // TState is the source of truth initi 阅读全文
posted @ 2024-01-22 03:03 Zhentiw 阅读(14) 评论(0) 推荐(0) 编辑
摘要:// Before declare function useState<T>(status: T[]): T; const loadingStatus = useState(["loading", "idle"]) // string type // after declare function u 阅读全文
posted @ 2024-01-22 02:57 Zhentiw 阅读(8) 评论(0) 推荐(0) 编辑
摘要:const routes = { user: ["get-user", "get-all-users"], comment: ["get-comment", "get-all-comments"] } as const type Routes = typeof routes type Possibl 阅读全文
posted @ 2024-01-22 02:52 Zhentiw 阅读(4) 评论(0) 推荐(0) 编辑
摘要:Overrides A common mistake, that has historically been difficult for TypeScript to assist with is typos when overriding a class method class Car { hon 阅读全文
posted @ 2024-01-17 11:13 Zhentiw 阅读(15) 评论(0) 推荐(0) 编辑
摘要:JS private field #serialNumbercannot be accessed outside class. But within class, it is accessible. JS private field can also be used to check class i 阅读全文
posted @ 2024-01-16 16:45 Zhentiw 阅读(8) 评论(0) 推荐(0) 编辑
摘要:In recent Typescript, it is possible to define static block class Car { static nextSerialNumber = 100 static isReady = false static { // this is the s 阅读全文
posted @ 2024-01-16 16:17 Zhentiw 阅读(6) 评论(0) 推荐(0) 编辑
摘要:Sometimes we have a free-standing function that has a strong opinion around what this will end up being, at the time it is invoked. For example, if we 阅读全文
posted @ 2023-12-30 22:10 Zhentiw 阅读(13) 评论(0) 推荐(0) 编辑
摘要:interface UnionBuilder<T = never> { add: <NewValue>() => UnionBuilder<T | NewValue>, fold: () => T } declare const u: UnionBuilder; const result = u . 阅读全文
posted @ 2023-12-27 22:21 Zhentiw 阅读(13) 评论(0) 推荐(0) 编辑
摘要:type NestedNumber = number | NestedNumber[] 阅读全文
posted @ 2023-12-19 21:33 Zhentiw 阅读(9) 评论(0) 推荐(0) 编辑
摘要:const returnWhatIPassIn = <const T extends any[]>(t: T) => { return t; }; // result is any[] in TS 5.2, but ['a', 'b', 'c'] in 5.3 const result = retu 阅读全文
posted @ 2023-12-13 01:55 Zhentiw 阅读(6) 评论(0) 推荐(0) 编辑
摘要:Let's say you're creating a component that has all the props of input but needs to add a label prop. You'll need to extend from the ComponentProps typ 阅读全文
posted @ 2023-10-10 14:59 Zhentiw 阅读(4) 评论(0) 推荐(0) 编辑
摘要:PubSub is one of the most foundational patterns for reactivity. Firing an event out with publish() allows anyone to listen to that event subscribe() a 阅读全文
posted @ 2023-10-04 02:19 Zhentiw 阅读(5) 评论(0) 推荐(0) 编辑
摘要:type WidenLiteral<T> = T extends string | number | boolean ? ReturnType<T["valueOf"]> : T; type Example1 = WidenLiteral<"abc"> // string type Example2 阅读全文
posted @ 2023-09-20 01:29 Zhentiw 阅读(4) 评论(0) 推荐(0) 编辑
摘要:Omit on Union type type Union = | { a: "a"; user?: string; } | { b: "b"; user?: string; }; type X = Omit<Union, "user">; // X is {} Using Distributive 阅读全文
posted @ 2023-09-02 19:12 Zhentiw 阅读(6) 评论(0) 推荐(0) 编辑
摘要:The `as` Prop in React Option 1: import { Equal, Expect } from '../helpers/type-utils'; export const Wrapper = <TProps extends keyof JSX.IntrinsicElem 阅读全文
posted @ 2023-08-31 19:53 Zhentiw 阅读(26) 评论(0) 推荐(0) 编辑
摘要:import { Router, useRouter } from "fake-external-lib"; export const withRouter = <TProps extends { router: Router }>( Component: React.ComponentType<T 阅读全文
posted @ 2023-08-30 15:07 Zhentiw 阅读(12) 评论(0) 推荐(0) 编辑
摘要:Fix forwardRef globally To jump ahead to the solution, uncommenting the following code from Stefan Baumgartner will globally override the value of for 阅读全文
posted @ 2023-08-29 14:41 Zhentiw 阅读(14) 评论(0) 推荐(0) 编辑
摘要:import { Equal, Expect } from "../helpers/type-utils"; type InputProps = React.ComponentProps<"input">; const COMPONENTS = { text: (props) => { return 阅读全文
posted @ 2023-08-29 14:34 Zhentiw 阅读(12) 评论(0) 推荐(0) 编辑
摘要:1. React.ReactNode import { useState } from "react"; import { createPortal } from "react-dom"; import { Equal, Expect } from "../helpers/type-utils"; 阅读全文
posted @ 2023-08-28 20:37 Zhentiw 阅读(10) 评论(0) 推荐(0) 编辑
摘要:Navigating to the type definition for lazy by CMD + click in local VS Code, or in the DefinitelyTyped repo. We can see the following definition: funct 阅读全文
posted @ 2023-08-28 17:54 Zhentiw 阅读(58) 评论(0) 推荐(0) 编辑

上一页 1 2 3 4 5 6 7 8 ··· 30 下一页
点击右上角即可分享
微信分享提示