Skip to content
This repository has been archived by the owner on Apr 30, 2019. It is now read-only.

Add support for "typings" property in package.json #208

Open
rbuckton opened this issue Aug 27, 2015 · 9 comments
Open

Add support for "typings" property in package.json #208

rbuckton opened this issue Aug 27, 2015 · 9 comments

Comments

@rbuckton
Copy link

In TypeScript 1.6 we are including a new module resolution semantics for CommonJS modules, which can be explicitly controlled using the new --moduleResolution command line option. Now, when you use --module commonjs or specify --moduleResolution node, module resolution for module names follows a new resolution strategy, based on the module resolution semantics for NodeJS.

When an absolute module name is resolved from the node_modules/ folder, an attempt is made to locate and parse the package.json file. TypeScript looks for a specific property, "typings" on the root of the package object.

This differs from how tsd currently handles type definitions embedded in package.json, which instead looks for a "typescript" property that contains an object with a "definitions" property.

Please consider adding support for the "typings" property, with the "typescript" object as a backwards-compatible fallback.

@blakeembrey
Copy link
Member

@rbuckton Thanks so much for this! What is the expected definition format for typings in 1.6? Can you use modules directly from the compiled output now? This is a pretty big win for TypeScript users, thanks for the update!

How does this work with "ambient modules" (is there a better name?) such the node definition itself? Basically modules that reference other modules but don't export anything themselves.

Edit: Will this work with other package managers like Bower?

@rbuckton
Copy link
Author

@blakeembrey When loading from the node_modules/ folder, this must be a declaration file. As far as any of your other questions about how module resolution works, I'd have to loop in @vladima.

@blakeembrey
Copy link
Member

Ok, thanks. Just trying to find the diff between what I've currently built/solved for the TSD future versions and what is coming up. Don't want to duplicate too much effort.

Currently, my solution is to use a combination of a typings map and an array for "ambient" definitions. I use the TypeScript compiler to then generate a single file for each dependency, with sub-dependencies inlined, that is added to the typings directory and I'm looking at using tsconfig.json for holding this information (under something like tsd.{dependencies,ambientDependencies}. This way, the output can be directly from the TypeScript compiler checked into NPM and people don't have to always write declaration files (it's possible for aliases of modules to happen, etc.).

By the sounds of it, there is a need for this to still exist. Can you point me to the implementation in TypeScript so I can start resolving what is now unnecessary?

@rbuckton
Copy link
Author

This change is in the release-1.6 branch on the TypeScript GitHub, and available to test via typescript@next on npm.

@alexeagle
Copy link
Contributor

We just finished migrating angular to this, and will roll it out tomorrow.
https://docs.google.com/document/d/1jiB1SHfM2AXacKdTbQBoPyKlp7ZSH-LBbfc5gzeMKVY/edit#
I am very excited about how easy this makes it for our users.

I believe users should not use tsd for angular2. tsd and DT are the side-channel to deliver typings for libraries that don't distribute their own, but we have better control over things like versioning semantics if we publish the typings in our primary distribution.

My choice of right behavior for tsd is to

  • check if the project already has an npm installation for the tsd typing requested. if so, log to the console "you already have typings for angular2 installed by npm, so there is no need to add angular2 to your tsd.json". Users should expect to be able to compile against the library directly.
  • otherwise, log to the console: "this package distributes typings in its NPM package, but it doesn't seem to be installed. Please npm install angular2"

@blakeembrey
Copy link
Member

Thanks @alexeagle, I've already added support for the typings field in the future branch and I had sent an email to try to have this discussion at the beginning of the week to Misko. If you want to discuss it, I'd love to jump on a call or something, but I don't think it makes sense to implement it like that. I actually read that at the beginning of the week too, and wanted to get a chance to properly discuss it.

@alexeagle
Copy link
Contributor

Yes, we would love to chat with you guys. Tsd remains really important for our users to be productive in Typescript.
We are all really busy getting ready for Angular Connect, so I'm not sure we'll find time this week. If not, maybe the week after the conference. Are you in San Francisco?

@blakeembrey
Copy link
Member

Yes, I actually work just off Market Street. Feel free to email if you want to move this discussion off here though 😄

@alexeagle
Copy link
Contributor

I emailed you at the address shown on github.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants