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

Module declarations must use "export declare" instead of "declare export". #8085

Merged
merged 9 commits into from May 13, 2022

Conversation

rmja
Copy link
Contributor

@rmja rmja commented May 11, 2022

↪️ Pull Request

This fixes #8079

💻 Examples

🚨 Test instructions

I am completely new to parcel and I have not found a good place to write a test for this. Some help would be appreciated.

✔️ PR Todo

  • Added/updated unit tests for this change
  • Filled out test instructions (In case there aren't any unit tests)
  • Included links to related issues/PRs

@mischnic
Copy link
Member

mischnic commented May 11, 2022

The tests are here: https://github.com/parcel-bundler/parcel/blob/v2/packages/core/integration-tests/test/ts-types.js

So I'd add example for module/namespace export to the index.ts and expected.d.ts here:
https://github.com/parcel-bundler/parcel/tree/v2/packages/core/integration-tests/test/integration/ts-types/main
(or if it only happens with reexports, then https://github.com/parcel-bundler/parcel/blob/v2/packages/core/integration-tests/test/integration/ts-types/exporting/index.ts)

@rmja
Copy link
Contributor Author

rmja commented May 11, 2022

@mischnic I have now added a test that passes. The PR now also fixes #7983.

@mischnic
Copy link
Member

You need to reformat shake.js with prettier (to make the lint CI job happy).

@rmja
Copy link
Contributor Author

rmja commented May 11, 2022

Lets hope that makes it happy:)

@mischnic
Copy link
Member

The PR now also fixes #7983.

But the test case you added probably doesn't cover that issue?

@rmja
Copy link
Contributor Author

rmja commented May 11, 2022

True, hang on.

@rmja
Copy link
Contributor Author

rmja commented May 11, 2022

@mischnic I have been unable to reproduce the bug when I run it as an integration test, but here is a minimal example that produces it.
https://github.com/rmja/unshift-issue

PS C:\Source\unshift-issue> npm run build

> build
> parcel build . ./augmenter

🚨 Build failed.

@parcel/transformer-typescript-types: Cannot read properties of undefined (reading 'unshift')

  TypeError: Cannot read properties of undefined (reading 'unshift')
  at visit (C:\Source\unshift-issue\node_modules\@parcel\transformer-typescript-types\lib\shake.js:60:24)
  at visitNodes (C:\Source\unshift-issue\node_modules\typescript\lib\typescript.js:87646:48)
  at Object.visitEachChild (C:\Source\unshift-issue\node_modules\typescript\lib\typescript.js:88126:56)
  at visit (C:\Source\unshift-issue\node_modules\@parcel\transformer-typescript-types\lib\shake.js:215:34)
  at visitNode (C:\Source\unshift-issue\node_modules\typescript\lib\typescript.js:87593:23)
  at Object.visitEachChild (C:\Source\unshift-issue\node_modules\typescript\lib\typescript.js:88123:222)
  at visit (C:\Source\unshift-issue\node_modules\@parcel\transformer-typescript-types\lib\shake.js:68:46)
  at visitNodes (C:\Source\unshift-issue\node_modules\typescript\lib\typescript.js:87646:48)
  at visitLexicalEnvironment (C:\Source\unshift-issue\node_modules\typescript\lib\typescript.js:87686:22)
  at Object.visitEachChild (C:\Source\unshift-issue\node_modules\typescript\lib\typescript.js:88234:55

It seems to be very similar to the test in https://github.com/parcel-bundler/parcel/tree/v2/packages/core/integration-tests/test/integration/ts-types/augmentation

@mischnic
Copy link
Member

mischnic commented May 12, 2022

The test will work once you bump typescript in the monorepo. So remove the typescript@>=3.0.0: block in yarn.lock and rerun Yarn.

Shouldn't the fix rather be

if(node.modifiers == null) node.modifiers = [];
node.modifiers.splice(...)

because currently the output is

module "original" {
    interface Person {
        name(): string;
    }
}

which I think is wrong?

Then you can also drop the node.modifiers.length && part

@rmja
Copy link
Contributor Author

rmja commented May 12, 2022

@mischnic I think you are right. I modified the linke so that modifiers is assigned with an empty array if it is undefined.

@mischnic
Copy link
Member

And please commit this change as well:

The test will work once you upgrade typescript in the monorepo. So remove the typescript@>=3.0.0: block in yarn.lock and rerun Yarn.

@rmja
Copy link
Contributor Author

rmja commented May 13, 2022

Sorry about that. Tbh I did not know what you meant, but I think I found out:)

@mischnic mischnic merged commit fe58766 into parcel-bundler:v2 May 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Typescript namespace export produces invalid types
2 participants