Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Good ways to use a fork of type definition like @types

Tags:

typescript

I'm using Typescript2.0 and @types currently. @types works fairly great. It enable us to use type definitions just by installing that package via npm.

However, actually I don't understand how it works. Because, I didn't writing any ///<reference~~ or writing something in tsconfig.json. But it works.

Whatever the reason it works, I want to use my type definition I forked from DefinitelyTyped repository. If I could use my type definition like @types, I guess it is great. But, I don't know that mechanism so how can I do that? Or, how the @types works?

like image 289
kyasbal Avatar asked Aug 16 '16 03:08

kyasbal


People also ask

What is definitely typed?

Definitely Typed is a project that provides a central repository of TypeScript definitions for NPM packages which do not have types.

Why use types TypeScript?

TypeScript's type system is very powerful because it allows expressing types in terms of other types. The simplest form of this idea is generics, we actually have a wide variety of type operators available to use. It's also possible to express types in terms of values that we already have.

How do you read TypeScript types?

In TypeScript, we have two different universes: the value and the type spaces. The type space is where types are defined and used to enable the compiler to do all the great magic. And the value space is the values in our programs like variables, constants, functions, value literals, and things that we have in runtime.


1 Answers

As far as I understand, @types is a nice interface for DefinitelyTyped that also supports a little bit of type dependency management. However, as you are still using DefinitelyTyped, you are (most of the time) just throwing everything into the global scope, making it accessible everywhere in your project.

So if you want to use different type declaration files, you can either try to install it via @types (if they come from DefinitelyTyped), just copy them over into your project, eg. under custom-typings/my-awesome-module.d.ts or use typings. Typings is probably the best option, as it gives you a wider range of sources you can download from, and you are not bound to using the global namespace.

I hope this helps 🙂 Let me know if you need more specific information.

like image 88
Pelle Jacobs Avatar answered Oct 02 '22 15:10

Pelle Jacobs