Loading...
Loading...
Use TypeScript for type-safe JavaScript: types, interfaces, generics, narrowing, tsconfig, modules, and strict mode. Use when writing or reviewing TypeScript, configuring tsconfig.json, defining types or interfaces, generics, type inference, or when the user mentions TypeScript, TS, or type checking.
npx skill4agent add enderpuentes/ai-agent-skills typescriptstricttsconfig.json| Concept | Syntax / note |
|---|---|
| Type annotation | |
| Interface | |
| Type alias | |
| Union | |
| Optional | |
| Generics | |
| Infer type from schema | Use library (e.g. 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"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): 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>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""strict": true"ES2022""ESNext""ESNext""NodeNext""bundler""NodeNext""@/*": ["./src/*"]z.infer<typeof schema>unknown!asstrict: true