Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Canonical way to search type definitions in typescript 2.0

Since typescript 2.0 instead of typings we are supposed to use npm install @types/<package-name>.

In typings we have typings search command for package lookups. My question is - what is the canonical way to search type definitions in @types?

So, to clarify, till now the workflow was:

  1. typings search <package-name>
  2. typings install [--global] <package-name>

Now:

  1. Question is about this step
  2. npm install --save-dev @types/<package-name>
like image 347
shabunc Avatar asked Oct 17 '16 23:10

shabunc


People also ask

Where does TypeScript look for type definitions?

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

How do I identify TypeScript types?

Use the typeof operator to check the type of a variable in TypeScript, e.g. if (typeof myVar === 'string') {} . The typeof operator returns a string that indicates the type of the value and can be used as a type guard in TypeScript.

What is ?: In TypeScript?

What does ?: mean in TypeScript? Using a question mark followed by a colon ( ?: ) means a property is optional. That said, a property can either have a value based on the type defined or its value can be undefined .

What are @types TypeScript?

What is a type in TypeScript. In TypeScript, a type is a convenient way to refer to the different properties and functions that a value has. A value is anything that you can assign to a variable e.g., a number, a string, an array, an object, and a function. When you look at this value, you can say that it's a string.


1 Answers

Not sure if this is possible with console, but Microsoft has provided this tool online to do that. You can find more details in this post.

I guess the idea is that all the names are maintained after @types/. So if the npm package name is my-test-package, then you should have @types/my-test-package if it exists at all and name can be used.

Unfortunately it seems that the NPM UI itself (and most likely API for the same reson) is rather bad with search for stuff that starts with @, so both @types and @angular does not give you the expected result. I do believe it's a bug and hope it'll be fixed.

like image 92
Ilya Chernomordik Avatar answered Sep 22 '22 18:09

Ilya Chernomordik