Loading...
Loading...
Compare original and translation side by side
stricttsconfig.jsontsconfig.jsonstrict| Concept | Syntax / note |
|---|---|
| Type annotation | |
| Interface | |
| Type alias | |
| Union | |
| Optional | |
| Generics | |
| Infer type from schema | Use library (e.g. Zod: |
| 概念 | 语法 / 说明 |
|---|---|
| 类型注解 | |
| 接口 | |
| 类型别名 | |
| 联合类型 | |
| 可选属性 | |
| 泛型 | |
| 从Schema推断类型 | 使用库(例如Zod: |
stringnumberbooleanbigintsymbolnumber[]Array<number>anyunknownconst name: string = "x"function greet(name: string): string { return "Hi " + name }{ name: string; age?: number }interface User { name: string; age?: number }string | number"a" | "b"stringnumberbooleanbigintsymbolnumber[]Array<number>anyunknownconst name: string = "x"function greet(name: string): string { return "Hi " + name }{ name: string; age?: number }interface User { name: string; age?: number }string | number"a" | "b"if (typeof x === "string") { ... }if (value) { ... }if (x === null) { ... }if ("name" in obj) { ... }function isFish(pet: Fish | Bird): pet is Fish { ... }kind: "circle"if (typeof x === "string") { ... }if (value) { ... }if (x === null) { ... }if ("name" in obj) { ... }function isFish(pet: Fish | Bird): pet is Fish { ... }kind: "circle"(a: string, b?: number) => booleanfunction first<T>(arr: T[]): T \| undefinedfunction longest<T extends { length: number }>(a: T, b: T): T(a: string, b?: number) => booleanfunction first<T>(arr: T[]): T \| undefinedfunction longest<T extends { length: number }>(a: T, b: T): Tinterface Point { x: number; y: number }extends[key: string]: numbertype K = keyof Usertype C = typeof configtype Name = User["name"]type Readonly<T> = { readonly [K in keyof T]: T[K] }type F = T extends string ? number : booleantype E = `on${Capitalize<Event>}`Partial<T>Required<T>Pick<T, K>Omit<T, K>Record<K, V>Exclude<T, U>Extract<T, U>NonNullable<T>ReturnType<F>Parameters<F>interface Point { x: number; y: number }extends[key: string]: numbertype K = keyof Usertype C = typeof configtype Name = User["name"]type Readonly<T> = { readonly [K in keyof T]: T[K] }type F = T extends string ? number : booleantype E = `on${Capitalize<Event>}`Partial<T>Required<T>Pick<T, K>Omit<T, K>Record<K, V>Exclude<T, U>Extract<T, U>NonNullable<T>ReturnType<F>Parameters<F>class C { prop: number; method(): void {} }constructor(public name: string) {}class D implements I {}class Child extends Parent {}class C { prop: number; method(): void {} }constructor(public name: string) {}class D implements I {}class Child extends Parent {}import { x } from "./file"export const x = 1export type { T }export default Appimport App from "./App"import { x } from "./file"export const x = 1export type { T }export default Appimport App from "./App""strict": true"ES2022""ESNext""ESNext""NodeNext""bundler""NodeNext""@/*": ["./src/*"]"strict": true"ES2022""ESNext""ESNext""NodeNext""bundler""NodeNext""@/*": ["./src/*"]z.infer<typeof schema>z.infer<typeof schema>unknown!asstrict: trueunknown!asstrict: true