Devzeebo Bifrost Typescript

Types

tomevault-io Updated

File contents

Types

Explicit types are necessary. Always use explicitly defined types and avoid anonymous types when possible. Only use interfaces when for module augmentation. Otherwise, use type definitions since they can be composed via discriminated unions. DO NOT write classes, ever. Instead of a class, write a type and export functions that take an instance of that type as the last argument (fp style).

// GOOD
export type MyTypeName = {
  prop: string;
  value: int;

  nestedThings: NestedType[];
};

export type NestedType = {
  id: string;
};
// BAD
export interface MyTypeName { // interface instead of type
  prop: string;
  value: int;

  nestedThings Array<{ // anonymous type
    id: string;
  }>;
};

Functions

Always use const fn = () => {} definitions over function fn() {} definitions unless you use this within the function. Always prefer "fp style" function declarations; args first data last. This is more composable.


Source: devzeebo/bifrost — distributed by TomeVault.

tomevault-io/skills-registry/tree/main/devzeebo--bifrost--typescript commit a4baf5d0c1

Frequently asked questions

npx skillmds@latest add tomevault-io/devzeebo-bifrost-typescript