Skip to content

Instantly share code, notes, and snippets.

@hughrawlinson
Last active February 5, 2020 00:56
Show Gist options
  • Save hughrawlinson/8cfe3f6c1f605262e37b1cc981f90845 to your computer and use it in GitHub Desktop.
Save hughrawlinson/8cfe3f6c1f605262e37b1cc981f90845 to your computer and use it in GitHub Desktop.
Typescript Questions

Questions I have about Typescript

Keeping a public list of questions that come up about Typescript so that I can easily share them I guess? I don't know.

  1. If you're writing a library, and you depend on a library, and your API requires args that you pass into the deeper library, should you wrap that library's types, or expose them? Is it bad practice to expose them? If so, how do you wrap them without going all the way to the bottom of the type stack?
  2. Really no ints? I did some searching around and the argument seems to be "js doesn't have ints at runtime so typescript can't have them". But a) javascript absolutely has ints at runtime thanks to some interpreter optimisations (even though yes they're not mentioned in the spec), and b) javascript doesn't have other typescript types at runtime, and typescript still has them, so what's the difference there?
  3. Maybe this is a bad pattern, but if I have some function that takes a list of values of a particular enum, and returns an object with keys corresponding to exactly that set of values, is there a way to have typescript know that, or do I just have to do a partial and manual checking? I guess maybe type parameters?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment