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

Getting svelte(missing-declaration) warnings for props #826

Closed
juzerzarif opened this issue Feb 19, 2021 · 4 comments
Closed

Getting svelte(missing-declaration) warnings for props #826

juzerzarif opened this issue Feb 19, 2021 · 4 comments
Labels
documentation Improvements or additions to documentation

Comments

@juzerzarif
Copy link

Describe the bug
I have this component code:

<script lang="ts">
  export let name = "John Doe";
</script>

<div>{name}</div>

I get a warning for svelte(missing-declaration) for name when I use it on the last line there. If I remove the inline export, the warning goes away:

<script lang="ts">
  let name = "John Doe";
  export { name }
</script>

<div>{name}</div>

Using svelte-check v1.1.35. Anyone know what I'm doing wrong here?

Expected behavior
No warning for prop usage.

System (please complete the following information):

  • OS: Windows
  • IDE: VSCode
  • Plugin/Package: svelte-check
@juzerzarif juzerzarif added the bug Something isn't working label Feb 19, 2021
@dummdidumm
Copy link
Member

I'm not able to reproduce this given your code snippet. For me a file with that content produces no warnings.
Did this work with previous versions? Could you try to find out which other things one needs in the environment for this to be reproducible (specific tsconfig.json settings maybe)?

@juzerzarif
Copy link
Author

Did some more digging around it, turns out having "module": "commonjs" in your tsconfig.json causes import and export statements to not get picked up at all. With that module generation config, any imported modules (import Button from './Button.svelete') or inline exported variable (export let name) will generate missing declaration warnings.

@dummdidumm
Copy link
Member

The problem is that TypeScript's transpilation is producing wrong results in this case. This is how the script content looks afterwards:

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.name = void 0;
exports.name = 'John Doe';
//# sourceMappingURL=Test.svelte.js.map

This is handed to the Svelte compiler which expects some kind of export let, does not find it and then produces something completely different than expected.

So to some extend it's "works as designed" from all parties involved but the combination leads to strange results. I'm not sure why you would want to set "module": "commonjs" anyway. Svelte is designed to run in the browser, where commonjs is not supported.

@juzerzarif
Copy link
Author

juzerzarif commented Feb 22, 2021

I have a shared tsconfig with a node application which is why module was set to commonjs. I agree that it doesn't make sense for compiling svelte, guess I can create two different configs for the node and svelte apps. Thanks for the troubleshooting!

Would this be a helpful thing to note in the docs somewhere? It took me a while to figure out exactly what was wrong with my setup since it's not immediately obvious, so maybe it'll help someone else...

@dummdidumm dummdidumm added documentation Improvements or additions to documentation and removed bug Something isn't working labels Feb 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants