摘要:
type RGB = [number, number, number] const palette: Record<'red' | 'blue' | 'green', string | RGB> = { red: [255, 0, 0], green: "#00ff00", blue: [0,0,2 阅读全文
摘要:
Typescript 4.9 supports an upcoming feature: Auto-accessors: class Person { accessor name: string constructor(name: string) { this.name = name } } Und 阅读全文
摘要:
Before version 4.9, you will get type error for the code: interface Context { packageJSON: unknown } function tryGetPackageName(context: Context) { co 阅读全文
摘要:
Implement the advanced util type MutableKeys, which picks all the mutable (not readonly) keys into a union. For example: type Keys = MutableKeys<{ rea 阅读全文
摘要:
Invoke by Promise: import { createMachine, interpret, send } from "xstate"; const machine = createMachine({ initial: "loading", states: { loading: { o 阅读全文
摘要:
function countBehavior(state, event) { if (event.type "INC") { return { ...state, count: state.count + 1 } } } function createActor(behavior, initialS 阅读全文