Typescript
Typescript
Run Typescript code
npx tsx src/code.ts
Enum
Docs
enum Direction {
Up = 1,
Down, // 2
Left, // 3
Right, // ...
}
enum Direction {
Up, // 0
Down, // ...
Left,
Right,
}
Modules
Docs
// @filename: hello.ts
export default function helloWorld() {
console.log("Hello, world!");
}
import helloWorld from "./hello.ts";
import { pi, phi, absolute } from "./maths.js";
import { pi as π } from "./maths.js";
Util Types
Docs
Partial<Type> // everything is optional
Omit<Type, Keys> // omit key from type
Type Assertion
Docs
onChange={(date) => field.handleChange(date as Date)}
`
``
## Interface
```typescript
interface SquareConfig {
name: string;
color?: string; // optional
width?: number;
readonly owner: string;
id: string | undefined;
}
Generics
function identity<Type>(arg: Type): Type {
return arg;
}