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

Issue with default export in typescript definitions #6079

Closed
maribethb opened this issue Apr 16, 2022 · 6 comments · Fixed by #6200
Closed

Issue with default export in typescript definitions #6079

maribethb opened this issue Apr 16, 2022 · 6 comments · Fixed by #6200
Labels
component: TypeScript issue: bug Describes why the code or behaviour is wrong

Comments

@maribethb
Copy link
Contributor

Describe the bug

TypeScript error when importing Blockly types, see stack trace section

To Reproduce

(taken from forum post: https://groups.google.com/g/blockly/c/hFuWPbkXRSk )

set allowSyntheticDefaultImports: true in tsconfig.json.
To reproduce:
ng new ws --create-application=true --routing=false --style=scss;
cd ws;
npm install blockly;
ng g c test
sed -i "2i import Blockly from 'blockly';" src/app/test/test.component.ts
ng serve

Stack Traces

 node_modules/blockly/blocks.d.ts:14:26 - error TS2497: This module can only be referenced with ECMAScript imports/exports by turning on the 'allowSyntheticDefaultImports' flag and referencing its default export.

import * as Blockly from './core';

Additional context

https://www.typescriptlang.org/tsconfig#esModuleInterop

I think this might go away if in blocks.d.ts we did import Blockly from 'blockly'; instead of import * as Blockly but I don't fully understand the intricacies of the module system we're using and how that interacts with the various tools being used. I think @cpcallen you are the expert here if this means anything to you.

@maribethb maribethb added issue: bug Describes why the code or behaviour is wrong component: TypeScript labels Apr 16, 2022
@joseluiz98
Copy link

I'm having that same problem :(

@FrancescoPandolfi
Copy link

Same problem here.

@johnnyoshika
Copy link

I have the same problem as well, but got around the issue by specifying "skipLibCheck": true in my tsconfig.json. It's not ideal, but got me unstuck. More details here:

https://groups.google.com/g/blockly/c/HCp55c18bQk/m/sLKBCjPHAQAJ

@maribethb
Copy link
Contributor Author

maribethb commented Jun 1, 2022

Hello @FrancescoPandolfi and @joseluiz98 and anyone else experiencing this issue, could you please try blockly beta 8.0.3-beta.1 and let me know if these errors are resolved and if there are any new ones? I think we have a fix for this problem in the beta and if it does not introduce new issues then we should be able to issue a patch release next week. Thanks!

@Chappie74
Copy link

Chappie74 commented Jun 8, 2022

I installed it, upgrading from 7.20211209.5.
One issue I found is the type binding for ToolboxCategory class may have changed.

Prior to the version change, this was working just fine. Not sure if its related, but just thought i'd add.

image
image

@maribethb
Copy link
Contributor Author

@Chappie74 Thanks for testing! Those errors are unfortunately regressions introduced in v8 - I think all of the interface classes got a bit weird. Ultimately this bug was hiding all of the other type declaration regressions since this was preventing any type checking from occurring. Feel free to file a separate bug for that, and in the meantime you can have the compiler ignore the problematic lines :/ sorry about that!

The good news is we are on the cusp of converting our whole codebase to TS ourselves so all of these inconsistencies will get a lot more obvious to us and hopefully less likely to occur in the future. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: TypeScript issue: bug Describes why the code or behaviour is wrong
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants