GithubHelp home page GithubHelp logo

utilities's Introduction

typescript-utilities-guide

a list of typescript helper libraries. advanced guides in typescript-cheatsheets will assume knowledge of these and refer people here.

There is a stage in every TypeScript journey where you struggle getting the types you want and eventually find a lifesaver blogpost like TypeScript Types You Should Know About. This cheatsheet accumulates them.

Automated JS to TS Conversion

JSON to TS type inference https://jvilk.com/MakeTypes/

Utility Types

Be familiar with the Utility Types that ship with TS. On top of that, here are handy Utility Types often used by TS practitioners, with explanation on what they do and how they can help. We will assume knowledge of mapped types and conditional types like Exclude<T, U> and ReturnType<T> but try to build progressively upon them.

Note: If you are new to conditional types, I highly recommend DJSheldrick's blogpost and talk on Conditional Types in TypeScript

Optionalize<T extends K, K>: Remove from T the keys that are in common with K
/**
 * Remove from T the keys that are in common with K
 */
type Optionalize<T extends K, K> = Omit<T, keyof K>;

An example usage is in our HOC section below.

Nullable<T> or Maybe<T>: Make a Type into a Maybe Type
/**
 * Make a Type into a Maybe Type
 */
type Nullable<T> = T | null
type Maybe<T> = T | undefined

Your choice of null or undefined depends on your approach toward missing values. Some folks feel strongly one way or the other.

Dictionary<T>: Dictionary of string, value pairs
/**
 * Dictionary of string, value pairs
 */
type Dictionary<T> = { [key: string]: T }

[key: string] is a very handy trick in general. You can also modify dictionary fields with Readonly or make them optional or Omit them, etc.

There also exist helper type libraries:

seriously, check some of these out, they represent a ton of accumulated typescript experience.

Type Testing

TypeScript Plugins

You can write plugins to modify typescript syntax itself. this is ADVANCED and not exactly recommended but here are some examples if you need them:

types to runtime

Misc

API Extractor provides an integrated, professional-quality solution for all these problems. It is invoked at build time by your toolchain and leverages the TypeScript compiler engine to:

  • Detect a project's exported API surface
  • Capture the contracts in a concise report designed to facilitate review
  • Warn about common mistakes (e.g. missing exports, inconsistent visibility, etc.)
  • Generate *.d.ts rollups with trimming according to release type
  • Output API documentation in a portable format that's easy to integrate with your content pipeline

example https://github.com/framer/api-docs/tree/master/api

documentation

  • it transpiles TypeScript code examples to JavaScript
  • it typechecks your TypeScript code examples
  • it allows you to include Docblocks from your sourcecode

https://twitter.com/phry/status/1302662810707660801?s=20

monorepo build tooling

  • https://rushstack.io/ - Specific strategy that integrates popular tools like NodeJS, TypeScript, ESLint, Prettier, Webpack, Jest for large scale monorepos from Microsoft
  • https://nx.dev/react/guides/js-and-ts - Nx is a general-purpose build system and a general-purpose CLI. It works with JavaScript, TypeScript, Java, C#, Go, etc.. The core plugins Nx comes with do work best with JavaScript or TypeScript.
  • https://blog.mgechev.com/2018/11/19/introduction-bazel-typescript-tutorial/ - Bazel is a powerful tool which can keep track of the dependencies between different packages and build targets. For simplicity, we can think of a build target as a build rule - for example, “build a TypeScript library”

Codegen from TypeScript

Data Structures

https://github.com/basarat/typescript-collections

utilities's People

Contributors

sw-yx avatar mjsarfatti avatar

Stargazers

Milad Vafaeifard avatar Sheldon Rupp avatar Drew Harris avatar Lungoupao Khongsai avatar Shresht avatar Mark Ledwich avatar David Lakin avatar Jaroslav Benc avatar  avatar shel avatar KatsiarynaSamuta avatar Stevon Crowder avatar Zoltan Peto avatar  avatar  avatar Yifan Xiang avatar Ilya Masalygin avatar ayush avatar  avatar Shakhzod Kudratov avatar Andy Williams avatar moxey.eth avatar Alex Lane avatar Harris avatar Nick Beattie avatar Shun Kakinoki avatar Wildan Zulfikar avatar beet avatar Dmytro Maslov avatar Muhamad Fajri avatar Mark Tan avatar foresightyj avatar  avatar Sushant Rajbanshi avatar Avin Lambrero avatar Wickramaranga Abeygunawardhana avatar Hamza Moiyadi avatar 波比小金刚 avatar Derek Lin avatar Patrick G avatar Scott Warren avatar DJ Collier avatar Sam Thorogood avatar Ben Johnston avatar drylint avatar Felix Jensen avatar  avatar yueyue avatar Eric Ogden avatar Derick M. avatar uwiew avatar echoLC avatar KainStar avatar jukanntenn avatar Dennis O'Keeffe avatar tomaswyz avatar jin avatar Neo Tan avatar Jack avatar tyankatsu avatar shippokun avatar yoonsang lee avatar Nick Adriaenssens avatar Apisit Ritreungroj avatar Max  avatar Olavo Amorim Santos avatar Самарин Иван avatar Michał Tkacz avatar Dawei Feng avatar Daelon Suzuka avatar hi94740 avatar Amir Muhammad Hakim avatar Andy Lu avatar Nicolás Giossa avatar Leslie avatar noah edward hall avatar  avatar Viktor Chernodub avatar Florinel Gorgan avatar pan93412 avatar chris montgomery avatar Ilya Medvedev avatar  avatar Thomas Silvestre avatar Adam Kwiatek avatar Dmitry Nedoboy avatar  avatar Sriram Somasundaram avatar Molecular Man avatar Odee avatar Tomasz Walotek avatar  avatar Nynne Just Christoffersen avatar Abboud Afaneh avatar Ryan Dennler avatar Tiago Ferreira avatar Ralph Kevin Y. Casipe avatar Esteban Mandirola avatar RHQYZ avatar  avatar

Watchers

Ted M. Young avatar James Cloos avatar Kamil Chmielewski avatar Andrii Pavliuk avatar bmac avatar FS.IO avatar Marcelo Dias avatar J avatar swyx avatar Sebastian Silbermann avatar Maciej Holyszko avatar

utilities's Issues

Utility type Omit is now included in the official TypeScript (since v3.5)

As the subject says :) Please see:

Question 1: Should we take it off this cheatsheet? (I can submit a PR)
Question 2: Should we point the link "Be familiar with the Utility Types that ship with TS" to the official TS handbook page on utility types, instead of a blog post, which is deemed to become stale at some point? (Again, happy to submit a PR :) )

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.