Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support typings in package.json by auto-generating immutable-nonambie… #808

Merged
merged 1 commit into from
Apr 15, 2016

Conversation

danielearwicker
Copy link
Contributor

As noted in #734 it is now possible to tell TypeScript where to find type defs in package.json by setting the typings property.

However the immutable.d.ts file is an ambient module (exports a module path name as a string). This is why pull request #779 didn't work. What is needed is a plain module that directly exports all the members of the namespace (there is no need for a top-level layer of wrapping as that is supplied by the external module).

There doesn't appear to be a way to define a module in one file and reuse it in both ambient and non-ambient contexts. So I've added a trivial bit of regex find-and-remove to the existing gulp task 'typedefs' to generate dist/immutable-nonambient.d.ts, and amended package.json to expose via the typings property.

This means immutable.d.ts can continue to be maintained as it is, as long as the two significant bits of wrapping are left as they are. Maybe they should have comments around them in immutable.d.ts to warn people against changing them?

Another option is to make the non-ambient version be definitive, as it only needs to be prefixed/suffixed as follows to make the equivalent of the existing ambient version:

declare module Immutable {

    // non-ambient file content goes here
}

declare module "immutable" {
  export = Immutable
}

Also I haven't removed the typescript property in package.json in case it is important for backward compatibility. It appears to be harmless.

@leebyron leebyron merged commit e437eeb into immutable-js:master Apr 15, 2016
@leebyron
Copy link
Collaborator

Great, thank you for this!

nexus-uw added a commit to nexus-uw/angular2-redux-starter that referenced this pull request May 2, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants