随笔分类 -  TypeScript

1 2 3 4 5 ··· 30 下一页
摘要:type ErrorWithMessage = { message: string } function isErrorWithMessage(error: unknown): error is ErrorWithMessage { return ( typeof error 'object' && 阅读全文
posted @ 2025-10-09 19:06 Zhentiw 阅读(6) 评论(0) 推荐(0)
摘要:async function runWithConcurrency(items, worker, maxConcurrency) { if (!items?.length) return; let i = 0; const workers: Array<Promise<void>> = []; as 阅读全文
posted @ 2025-08-31 20:15 Zhentiw 阅读(6) 评论(0) 推荐(0)
摘要:Runner function: function run(genFn) { const it = genFn() let state = { done: false, value: undefined } step() function step(isError, arg) { try { sta 阅读全文
posted @ 2025-08-09 22:29 Zhentiw 阅读(8) 评论(0) 推荐(0)
摘要:You’re seeing that const scores = {} satisfies Record<string,number> does check at compile-time “hey, {} can be a Record<string,number>”, but it doesn 阅读全文
posted @ 2025-06-23 02:31 Zhentiw 阅读(5) 评论(0) 推荐(0)
摘要:// 内置工具类型 // 1. Partial<T>:将类型 T 的所有属性变为可选属性。 // 2. Required<T>:将类型 T 的所有可选属性变为必需属性。 // 3. Readonly<T>:将类型 T 的所有属性变为只读属性。 // 4. Record<K, T>:将类型 K 的所有 阅读全文
posted @ 2025-05-11 14:53 Zhentiw 阅读(23) 评论(0) 推荐(0)
摘要:type Watcher<T> = { on<K extends keyof T & string>( eventName: `${K}Changed`, callback: (oldValue: T[K], newValue: T[K]) => void ): void; }; declare f 阅读全文
posted @ 2025-05-06 14:06 Zhentiw 阅读(7) 评论(0) 推荐(0)
摘要:Using T extends any ? {...} : never helps to see the type result Example: type DeepReadonly<T extends Record<string, any>> = T extends any ? { readonl 阅读全文
posted @ 2025-04-05 19:47 Zhentiw 阅读(13) 评论(0) 推荐(0)
摘要:export function singleton< T extends new (...args: any[]) => object >(classCtor: T): T { let instance!: InstanceType<T> const proxy = new Proxy(classC 阅读全文
posted @ 2025-03-04 15:19 Zhentiw 阅读(14) 评论(0) 推荐(0)
摘要:The example case covers room numbers validation: it must start with an uppercase letter followed by three digits. z.custom allows the creation of a br 阅读全文
posted @ 2025-03-04 14:46 Zhentiw 阅读(34) 评论(0) 推荐(0)
摘要:Instead of creating many small schemas, which can complicate maintenance, Zod allows for the extraction of specific parts of a schema using the concep 阅读全文
posted @ 2025-03-04 14:42 Zhentiw 阅读(46) 评论(0) 推荐(0)
摘要:When you try to import image in typescript project, it will report issue import logo from "./assets/react.svg" What you can do is, create a types.d.ts 阅读全文
posted @ 2025-02-21 16:10 Zhentiw 阅读(17) 评论(0) 推荐(0)
摘要:整合 TypeScript 准备工作 首先我们需要有一个基于 ts 的项目。 第一步通过 npm init -y 初始化项目 接下来通过: npm install typescript 局部安装 typescript。 之后还需要生成 typescript 的配置文件,通过命令: npx tsc - 阅读全文
posted @ 2025-01-25 18:45 Zhentiw 阅读(47) 评论(0) 推荐(0)
摘要:The Input is Different than the Output We've reached the point with Zod where our input is different than our output. In other words, you can generate 阅读全文
posted @ 2024-12-21 19:19 Zhentiw 阅读(8) 评论(0) 推荐(0)
摘要:Define a component with props and defualt props value <script setup lang="ts"> import { ref, onMounted } from 'vue' import fetchCount from '../service 阅读全文
posted @ 2024-11-27 22:33 Zhentiw 阅读(54) 评论(0) 推荐(0)
摘要:<template> <router-link class="event-link" :to="{ name: 'EventDetails', params: { id: event.id } }" > <div class="event-card"> <span>@{{ event.time }} 阅读全文
posted @ 2024-11-27 03:08 Zhentiw 阅读(12) 评论(0) 推荐(0)
摘要:/** * Utility for extracting the parameters from a function overload (for typed emits) * https://github.com/microsoft/TypeScript/issues/32164#issuecom 阅读全文
posted @ 2024-11-25 21:30 Zhentiw 阅读(28) 评论(0) 推荐(0)
摘要:We have a module: const key = Symbol('key') export class A { [key] = 1 value () { console.log(this[key]) } } It seems that keyis not expose to outside 阅读全文
posted @ 2024-11-25 21:10 Zhentiw 阅读(12) 评论(0) 推荐(0)
摘要:const BookingSchema = z.object({ roomType: z.string(), dueDate: z .string({ message: "invalid due date", }) .date('date format is wrong'), numberOfGue 阅读全文
posted @ 2024-11-19 15:50 Zhentiw 阅读(21) 评论(0) 推荐(0)
摘要:export enum EffectFlags { /** * ReactiveEffect only */ ACTIVE = 1 << 0, RUNNING = 1 << 1, TRACKING = 1 << 2, NOTIFIED = 1 << 3, DIRTY = 1 << 4, ALLOW_ 阅读全文
posted @ 2024-11-19 02:51 Zhentiw 阅读(18) 评论(0) 推荐(0)
摘要:type BanType<T, E> = T extends E ? never : T; type BanDate<T> = BanType<T, Date>; function log<T>(x: BanDate<T>) { console.log() } log(new Date()) // 阅读全文
posted @ 2024-09-09 14:55 Zhentiw 阅读(11) 评论(0) 推荐(0)

1 2 3 4 5 ··· 30 下一页