Clean code in TypeScript
The TypeScript handbook’s Do’s and Don’ts are about types: number, string and boolean, never Number, String or Boolean; no any; unions and optional parameters over overloads; void for an ignored callback value.
What does the TypeScript handbook ask for?
Don’t ever use the types Number, String, Boolean, Symbol, or Object
source
From TypeScript handbook, Do’s and Don’ts. For names, see the JavaScript page.
What does cleaner TypeScript look like?
function label(value: any): String {
return "Item " + value;
}
function onSave(callback: (id: number) => any) {
callback(42);
}function label(value: number | string): string {
return `Item ${value}`;
}
function onSave(callback: (id: number) => void): void {
callback(42);
}