Support typings in package.json by auto-generating immutable-nonambie… #808
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As noted in #734 it is now possible to tell TypeScript where to find type defs in
package.json
by setting thetyping
s 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 amendedpackage.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 inimmutable.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:
Also I haven't removed the
typescript
property inpackage.json
in case it is important for backward compatibility. It appears to be harmless.