Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where can I find documentation for TypeScript's built-in types and standard library?

Tags:

typescript

I love working with TypesScript (as a former C# dev) and I spend hours every month browsing through the online documentation.

However, I can't seem to find documentation about built-in types such as Map<T1,T2>, etc.

The documentation refers to the standard library in a few places, but I also cannot seem to find documentation for that (for example, the Partial<T> awesome class.

Am I just missing it?

like image 281
Eric Liprandi Avatar asked Oct 11 '17 19:10

Eric Liprandi


People also ask

Where are TypeScript types defined?

TypeScript automatically finds type definitions under node_modules/@types , so there's no other step needed to get these types available in your program.

What are D TS files TypeScript?

The "d. ts" file is used to provide typescript type information about an API that's written in JavaScript. The idea is that you're using something like jQuery or underscore, an existing javascript library. You want to consume those from your typescript code.

What is TypeScript declaration file?

Declaration files, if you're not familiar, are just files that describe the shape of an existing JavaScript codebase to TypeScript. By using declaration files (also called . d. ts files), you can avoid misusing libraries and get things like completions in your editor.


1 Answers

This is not a TypeScript standard library, it's ECMAScript, so you won't find a TS-specific reference.

Luckily there are lots of references for that around. I normally tend to just do a quick Google search and end up in places like MDN, which IMO the best place for modern JS reference. If you like Microsoft and MSDN stuff, they have their own JS-specific reference, but I don't think it's as good as MDN.

The problem with the above is that it doesn't really refer to how types are treated by TS. You'll find a reference to Map(), not to Map<T1, T2>(). So which type to use where, especially where generics come into play, is a bit implied.

I found that to quickly check how those types are treated, inspecting a type (e.g. hitting F12 when your cursor is over a type in Visual Studio Code) suffices. It'll take you to the specific (internal) definition of the type. For example, for Map, you'll be taken to this piece of code. All the definition libs are also available online if you need to check them beforehand.

like image 195
zeh Avatar answered Nov 03 '22 10:11

zeh