01 2024 档案

摘要:Our project might have a file structure like Our project might have a file structure like data/ book.ts // A model for Book records magazine.ts // A m 阅读全文
posted @ 2024-01-31 16:02 Zhentiw 阅读(15) 评论(0) 推荐(0) 编辑
摘要:type AnyProppertyKey = keyof any Example: type Example = Record<AnyProertyKey, any> 阅读全文
posted @ 2024-01-31 15:10 Zhentiw 阅读(1) 评论(0) 推荐(0) 编辑
摘要:Since typescript 5, we are able to add constraints over infer. Following code doesn't apply constraints, so the inferred element could be stringand nu 阅读全文
posted @ 2024-01-29 23:44 Zhentiw 阅读(5) 评论(0) 推荐(0) 编辑
摘要:type OneArgFn<A = any> = (firstArg: A, ..._args: any[]) => void type GetFirstArg<T> = T extends OneArgFn<infer R> ? R : never; // Test case function f 阅读全文
posted @ 2024-01-29 23:39 Zhentiw 阅读(2) 评论(0) 推荐(0) 编辑
摘要:Particularly if you use a bundler like webpack, parcel or snowpack, you may end up importing things that aren’t .js or .ts files For example, maybe yo 阅读全文
posted @ 2024-01-29 14:58 Zhentiw 阅读(4) 评论(0) 推荐(0) 编辑
摘要:Node.js 13.2.0 introduced support for native ES modules. This means you can natively run code containing thing like import { Foo } from 'bar', use top 阅读全文
posted @ 2024-01-29 14:47 Zhentiw 阅读(10) 评论(0) 推荐(0) 编辑
摘要:Let's say we need to use a library with commonJS code. class Melon { cutIntoSlices() { } } module.exports = Melon Then we want to import this inside o 阅读全文
posted @ 2024-01-28 20:36 Zhentiw 阅读(5) 评论(0) 推荐(0) 编辑
摘要://////////////////////////////////////////////////////// // @filename: berries/raspberry.ts export class Raspberry { constructor(public color: 'red' | 阅读全文
posted @ 2024-01-28 20:14 Zhentiw 阅读(4) 评论(0) 推荐(0) 编辑
摘要:const NAME = "Matt"; TypeScript is telling us we can't redeclare the name variable because it has already been declared inside of lib.dom.d.ts. The in 阅读全文
posted @ 2024-01-23 21:32 Zhentiw 阅读(15) 评论(0) 推荐(0) 编辑
摘要:Example code: const routingConfig = { routes: [ { path: "home", component: "HomeComponent", }, { path: "about", component: 12, }, { path: "contact", c 阅读全文
posted @ 2024-01-23 21:16 Zhentiw 阅读(3) 评论(0) 推荐(0) 编辑
摘要:Creational patterns provide object creation mechanisms that increase flexibility and reuse of existing code. Factory method: Provides an interface for 阅读全文
posted @ 2024-01-23 15:11 Zhentiw 阅读(6) 评论(0) 推荐(0) 编辑
摘要:class Fish { swim(): void {} } class Bird { fly(): void {} } switch(true) { case val instanceof Bird: val.fly() break case val instanceof Fish: val.sw 阅读全文
posted @ 2024-01-22 14:44 Zhentiw 阅读(2) 评论(0) 推荐(0) 编辑
摘要:Normally you need to put require("dotenv").config() console.log(process.env.TEST) to access env vars WIth --node-fileflag you don't need to do that an 阅读全文
posted @ 2024-01-22 14:25 Zhentiw 阅读(34) 评论(0) 推荐(0) 编辑
摘要:const interValueFromColor = <N extends string, C extends string, T extends number>(colorTag: `${N}-${C}-${T}`) => { const [namespace, color, tone] = c 阅读全文
posted @ 2024-01-22 03:08 Zhentiw 阅读(8) 评论(0) 推荐(0) 编辑
摘要:// 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) 编辑

点击右上角即可分享
微信分享提示