-
use
never
isntead ofunknown
whenever possible -
Last resort pseudo-any types:
export type EnumType = { [key: string]: string }; export type ObjectType = { [key: string]: unknown | unknown[] };
-
An example of looping through an object's keys in the actual code:
export const as = (table: string, sqlFields: EnumType, fields: EnumType) => { let output: string[] = []; for (const i in sqlFields) { const row = `${table}.${sqlFields[i]} as ${fields[i]}`; output.push(row); } return output; };
-
Make an object immutable
const obj = { foo: 'bar' } as const
-
Required<...>
is the opposite ofPartial<...>
-
protected
methods of TS classes are private, but accessible by child classes