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?
Definitely Typed is a project that provides a central repository of TypeScript definitions for NPM packages which do not have types.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With