Skip to content

Instantly share code, notes, and snippets.

@kasper573
Last active February 7, 2023 12:33
Show Gist options
  • Save kasper573/ee7a01046356cf39b348fab47dbfde6b to your computer and use it in GitHub Desktop.
Save kasper573/ee7a01046356cf39b348fab47dbfde6b to your computer and use it in GitHub Desktop.

Tings personal awesome typescript cheat sheet

  • A class is a type that can be instantiated
  • interfaces should be used to define a common pattern that many classes wants to implement
  • 'any' is commonly used when integrating typescript with javascript libraries
  • difference between type and interface: types can be inferred, interfaces cannot

Terminology:

  • Fancy english words:

    • explicit: stated clearly and in detail, leaving no room for confusion or doubt.
    • implicit: suggested though not directly expressed
  • Typescript concepts:

    • type definitions
      • classes, interfaces and types
    • variable type definitions
      • Example:
        let test: string = 'hello';
        
      • Can be explicit or implicit
        • implicit:
          const test = 'hello';
          
        • explicit:
          const test: string = 'hello';
          
      • Special case:
        const test = {foo: 'bar'}; // implicit type will be inferred by typescript
        
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment