typed-ember / ember-cli-typescript

Use TypeScript in your Ember.js apps!
https://docs.ember-cli-typescript.com
MIT License
363 stars 99 forks source link

`npm publish` fails - No declaration file for module `'dummy/app'` #1448

Closed MrChocolatine closed 2 years ago

MrChocolatine commented 3 years ago

Also asked on Discord: https://discord.com/channels/480462759797063690/484421406659182603/885928438542794752

Please paste the output of ember -v here

ember-cli: 3.24.0 node: 14.17.6 os: darwin x64

Please paste the output of tsc -v here

Version 4.4.3

Please paste the version of ember-cli-typescript and ember-cli-typescript-blueprints here

yarn list v1.22.11
├─ @glimmer/component@1.0.4
│  └─ ember-cli-typescript@3.0.0
├─ ember-cli-typescript-blueprints@3.0.0
├─ ember-cli-typescript@4.2.1
└─ ember-load-initializers@2.1.2
   └─ ember-cli-typescript@2.0.2

Please paste your tsconfig.json and tslint.json or eslint.json (if applicable) below

Not applicable.

What are instructions we can follow to reproduce the issue?

ember new sample
cd ./sample
ember install ember-cli-typescript

# Runs without any issue
yarn run prepack

# Add types for `qunit-dom`
# https://github.com/simplabs/qunit-dom/tree/v2.0.0#typescript

# Fails (see error log below)
yarn run prepack
The error log from the last command `yarn run prepack` ```shell tests/test-helper.ts:1:25 - error TS7016: Could not find a declaration file for module 'dummy/app'. '/Users/_/Dev/emberjs/__test-addon-with-typescript/tests/dummy/app/app.js' implicitly has an 'any' type. 1 import Application from 'dummy/app'; ~~~~~~~~~~~ Found 1 error. Command failed with exit code 1: tsc --allowJs false --noEmit false --rootDir /Users/_/Dev/emberjs/__test-addon-with-typescript --isolatedModules false --declaration --declarationDir /Users/_/Dev/emberjs/__test-addon-with-typescript/e-c-ts-precompile-14668 --emitDeclarationOnly --pretty true tests/test-helper.ts:1:25 - error TS7016: Could not find a declaration file for module 'dummy/app'. '/Users/_/Dev/emberjs/__test-addon-with-typescript/tests/dummy/app/app.js' implicitly has an 'any' type. ```

Now about that bug. What did you expect to see?

Add-on correctly published to npmjs.

What happened instead?

⬆️ See the error log above


My current fix is to write declare module 'dummy/app'; in the file /types/dummy/index.d.ts. Do you think it is wise? Do you think of a better solution?

Then exactly same issue when creating a unit-test for an Initializer or an Instance-Initializer and renaming the file with the extension .ts, the command yarn run prepack fails at the line import { initialize } from 'dummy/instance-initializers/my-thing'.

MrChocolatine commented 2 years ago

Answer: https://discord.com/channels/480462759797063690/484421406659182603/888036425348550656

@dfreeman: Unfortunately I don't have time to write up a full response on the issue you opened right now, but the short answer is that ts:precompile sets allowJs: false when it runs @dfreeman: IMO (speaking only for myself and not any of the rest of the typed-ember folks) we shouldn't be setting allowJs: true in the default blueprint in the first place @dfreeman: but I think that's the root of your problem @dfreeman: either adding a .d.ts file alongside tests/dummy/app/app.js or actually converting that file to TS should solve your problem @dfreeman: the declare module you suggested should also be fine