TypeScript Input
JavaScript Output
string
Text data
let name: string = "Alice";
number
Integer or float
let age: number = 30;
boolean
True or false
let active: boolean = true;
any
Disables type checking
let value: any = "anything";
unknown
Type-safe any
let value: unknown = fetch(...);
void
Function returns nothing
function log(): void { console.log(...); }
never
Unreachable type
function error(): never { throw Error(); }
Partial<T>
All properties optional
type PartialUser = Partial<User>;
Required<T>
All properties required
type RequiredUser = Required<User>;
Pick<T, K>
Select specific properties
type Summary = Pick<User, 'name'>;
Omit<T, K>
Exclude specific properties
type NoEmail = Omit<User, 'email'>;
Record<K, T>
Map keys to type
type Status = Record<'on'|'off', boolean>;
Readonly<T>
Immutable properties
type ReadonlyUser = Readonly<User>;
ReturnType<T>
Function return type
type R = ReturnType<typeof fn>;
Parameters<T>
Function parameter types
type P = Parameters<typeof fn>;
Interface
interface User { name: string; }
Generic Function
function identity<T>(arg: T): T { return arg; }
Enum
enum Status { Active, Inactive }
Class with Modifiers
class User { private id: number; }
Type Guard
function isString(x): x is string { }
Mapped Type
type Getters<T> = { [K in keyof T]: () => T[K] }
Conditional Type
type IsString = T extends string ? true : false;
Type Alias
type ID = string | number;
Async Function
async function fetch(): Promise<Data> { }
Decorator Pattern
@Component class MyClass { }