随笔分类 -  TypeScript

上一页 1 ··· 4 5 6 7 8 9 10 11 12 ··· 30 下一页
摘要:import { getAnimatingState } from "fake-animation-lib"; import { Equal, Expect } from "../helpers/type-utils"; const animatingState = getAnimatingStat 阅读全文
posted @ 2023-02-23 15:12 Zhentiw 阅读(212) 评论(0) 推荐(0)
摘要:import React from 'react'; declare global { namespace JSX { interface IntrinsicElements { 'custom-element': { children?: React.ReactNode; title?: stri 阅读全文
posted @ 2023-02-22 15:38 Zhentiw 阅读(53) 评论(0) 推荐(0)
摘要:import { Equal, Expect } from '../helpers/type-utils'; import { F } from 'ts-toolbelt'; interface Fruit { name: string; price: number; } export const 阅读全文
posted @ 2023-02-22 15:17 Zhentiw 阅读(18) 评论(0) 推荐(0)
摘要:import { it } from 'vitest'; interface Events { click: { x: number; y: number; }; focus: undefined; } type LookUpEvents<K extends keyof Events> = Even 阅读全文
posted @ 2023-02-18 16:15 Zhentiw 阅读(24) 评论(0) 推荐(0)
摘要:import { expect, it } from "vitest"; import { fetchUser } from "fake-external-lib"; type Middleware<TInput, TOutput> = (input: TInput) => TOutput; cla 阅读全文
posted @ 2023-02-15 16:48 Zhentiw 阅读(30) 评论(0) 推荐(0)
摘要:From previous post, Builder pattern - 03 If we do the following changes: - class TypeSafeStringMap<TMap extends Record<string, string> = {}> { + class 阅读全文
posted @ 2023-02-14 15:07 Zhentiw 阅读(23) 评论(0) 推荐(0)
摘要:import { expect, it } from 'vitest'; class TypeSafeStringMap<TMap extends Record<string, string> = {}> { private map: TMap; constructor() { this.map = 阅读全文
posted @ 2023-02-14 14:24 Zhentiw 阅读(16) 评论(0) 推荐(0)
摘要:export class BuilderTuple<TList extends any[] = []> { list: TList; constructor() { this.list = [] as any; } push<TNum extends number>(num: TNum): Buil 阅读全文
posted @ 2023-02-13 18:12 Zhentiw 阅读(19) 评论(0) 推荐(0)
摘要:The builder pattern is a design pattern commonly used in OOP. It is used to create complex objects step by step throught a series of methods, each of 阅读全文
posted @ 2023-02-13 16:41 Zhentiw 阅读(28) 评论(0) 推荐(0)
摘要:file1: import { expect, it } from "vitest"; /** * Here, we've actually got _multiple_ problem files! * Make sure to to check problem.2.ts too. */ decl 阅读全文
posted @ 2023-02-10 21:09 Zhentiw 阅读(23) 评论(0) 推荐(0)
摘要:We have the following code: class Form<TValues> { error?: string; constructor( public values: TValues, private validate: (values: TValues) => string | 阅读全文
posted @ 2023-02-10 21:03 Zhentiw 阅读(21) 评论(0) 推荐(0)
摘要:import { it } from 'vitest'; import { Brand } from '../helpers/Brand'; type Valid<T> = Brand<T, 'Valid'>; interface PasswordValues { password: string; 阅读全文
posted @ 2023-02-10 20:44 Zhentiw 阅读(17) 评论(0) 推荐(0)
摘要:import { it } from 'vitest'; import { Equal, Expect } from '../helpers/type-utils'; export const isDivElement = (element: unknown): element is HTMLDiv 阅读全文
posted @ 2023-02-10 20:38 Zhentiw 阅读(14) 评论(0) 推荐(0)
摘要:import { expect, it } from "vitest"; import { Equal, Expect } from "../helpers/type-utils"; export const values = ["a", "b", undefined, "c", undefined 阅读全文
posted @ 2023-02-10 02:10 Zhentiw 阅读(25) 评论(0) 推荐(0)
摘要:import { Equal, Expect } from "../helpers/type-utils"; const obj = { a: 1, b: 2, c: 3, } as const; type ObjKey = keyof typeof obj; //Type '"a"' is not 阅读全文
posted @ 2023-02-08 15:57 Zhentiw 阅读(36) 评论(0) 推荐(0)
摘要:// You'll need to use function overloads to figure this out! function useData<T>(params: { fetchData: () => Promise<T>; initialData?: T }): { getData: 阅读全文
posted @ 2023-02-08 14:18 Zhentiw 阅读(23) 评论(0) 推荐(0)
摘要:Define function / variable in global scope globalThis.myFunc = () => true; // doesn't compile globalThis.myVar = 1; // doesn't compile it("Should let 阅读全文
posted @ 2023-02-06 21:04 Zhentiw 阅读(28) 评论(0) 推荐(0)
摘要:In this exercise, we're going to look at a really interesting property of branded types when they're used with index signatures. Here we have our User 阅读全文
posted @ 2023-02-06 03:38 Zhentiw 阅读(34) 评论(0) 推荐(0)
摘要:type A = {other: 'string', url: 'string'} type B = {other: 'string', ids: 'string'} type Exclusive< T extends Record<PropertyKey, unknown>, U extends 阅读全文
posted @ 2023-02-03 18:40 Zhentiw 阅读(20) 评论(0) 推荐(0)
摘要:import { Equal, Expect } from "../helpers/type-utils"; const obj = { a: 1, b: 2, c: 3, } as const; type ObjKey = keyof typeof obj; // If don't pass in 阅读全文
posted @ 2023-02-02 16:04 Zhentiw 阅读(25) 评论(0) 推荐(0)

上一页 1 ··· 4 5 6 7 8 9 10 11 12 ··· 30 下一页