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

Improve support for Typescript declare structures #1356

Merged
merged 7 commits into from
May 23, 2019

Conversation

christophercurrie
Copy link
Contributor

This change improves support various forms used in Typescript declaration files. It's often necessary to change import resolution to prefer '.d.ts' files over '.js' files, but doing so breaks existing import resolution for certain types of UMD modules (React, for example).

This patch has two improvements:

  • It adds support for the export declare function foo() syntax, which wasn't previously recognized
  • It adds support for the export = Namespace syntax for exporting everything in a namespace.

The import/named tests were updated to add both variations as additional test files.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.09%) to 97.844% when pulling aa290bb on christophercurrie:typescript-declare into 1edbbd0 on benmosher:master.

@coveralls
Copy link

coveralls commented May 11, 2019

Coverage Status

Coverage increased (+0.01%) to 97.947% when pulling b52bf3e on christophercurrie:typescript-declare into 1edbbd0 on benmosher:master.

Copy link
Member

@ljharb ljharb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems reasonable.

utils/unambiguous.js Outdated Show resolved Hide resolved
christophercurrie and others added 2 commits May 12, 2019 09:39
Co-Authored-By: Jordan Harband <ljharb@gmail.com>
@christophercurrie
Copy link
Contributor Author

Thanks. Incorporated your change and fixed the issues with older typescript parsers.

src/ExportMap.js Outdated Show resolved Hide resolved
@christophercurrie
Copy link
Contributor Author

I don’t disagree, but I was trying to follow the style of the file. Happy to make a change, just let me know.

@ljharb
Copy link
Member

ljharb commented May 13, 2019

Thanks, it'd be great to improve the readability in this PR :-) it's not a blocker, tho.

Copy link
Member

@ljharb ljharb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, much better :-)

src/ExportMap.js Outdated Show resolved Hide resolved
src/ExportMap.js Outdated Show resolved Hide resolved
christophercurrie and others added 2 commits May 13, 2019 14:56
Co-Authored-By: Jordan Harband <ljharb@gmail.com>
Co-Authored-By: Jordan Harband <ljharb@gmail.com>
@christophercurrie
Copy link
Contributor Author

Applied.

@ljharb ljharb merged commit 17beb33 into import-js:master May 23, 2019
@joaovieira
Copy link
Contributor

joaovieira commented Oct 30, 2019

@christophercurrie this does not cover situations like:

export = supertest;

declare function supertest(app: any): supertest.SuperTest<supertest.Test>;
declare namespace supertest { ... }

and

import { snakeCase } from "./index";
export = snakeCase;

I've raised #1527 for that.

This was already a great help to understand what was going on :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

None yet

4 participants