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

TypeScript Errors ts(2440) with Svelte for VS Code starting v101.1.0 #294

Closed
vatro opened this issue Jul 8, 2020 · 2 comments
Closed

TypeScript Errors ts(2440) with Svelte for VS Code starting v101.1.0 #294

vatro opened this issue Jul 8, 2020 · 2 comments
Labels
bug Something isn't working Fixed Fixed in master branch. Pending production release.

Comments

@vatro
Copy link
Contributor

vatro commented Jul 8, 2020

Describe the bug
Yesterday with v101.0.0 I finished migrating my Svelte components library to TS with almost no / no severe (correctly compiling) TS-errors. Today with v101.1.1 (checked: starting with v101.1.0) I get a bunch of ts(2440) (+ a lot of resulting) errors: Import declaration conflicts with local declaration of 'Foo', while everything is still compiling / building correctly as with v101.0.0. I'm not sure though if this is a bug or a feature which was not functioning correctly in v101.0.0.

Running svelte-check reports same errors.

To Reproduce
I'm going to describe as simple as possible how I'm building the mentioned library.

It's a library of Svelte components 'target_lib' wrapping modules of library 'source_lib'. Svelte wrapper-components and their corresponding modules from 'source_lib' have identical names:

// Svelte wrapper-component 'Foo.svelte'
<script lang="typescript">
   import { Foo } from 'source_lib'
</script>

// 'target_lib.ts'
export { default as Foo } from './components/Foo.svelte'
export * from 'source_lib'

When building 'target_lib' Rollup is renaming duplicates like this in the 'target_lib.mjs':

Foo from 'source_lib' keep name Foo
Svelte wrapper-Foo-components are being renamed to Foo_1 (+ _1)

This might seem like bad practice but is exactly how I want it to be, it works as intended: Svelte 'target_lib'-'Foo' components override (and utilize) corresponding 'source_lib'-'Foo' components when e.g.

//Test.svelte
<script>
   import { Foo } from 'target_lib'
</script>

<Foo />

Expected behavior
I don't know what to expect, because I don't know if ts(2440) errors are a bug or a feature. Rollup builds o.k. as expected / as before despite the "new" errors.

Actually it feels like correct behavior that these conflicts are being reported, but on the other hand it makes Rollup's ability to manage such cases obsolete and then it feels kind of wrong again. I would just like to get a clear response if this is intended / correct behavior, then I would know if I have to think of another solution / fix / find workaround or wait for an update. Thanks!

System (please complete the following information):

  • OS: Windows 10
  • IDE: VSCode
  • Plugin/Package:
    Svelte for VSCode
 "devDependencies": {
    "@rollup/plugin-alias": "^3.1.1",
    "@rollup/plugin-node-resolve": "^8.1.0",
    "@rollup/plugin-typescript": "^5.0.1",
    "prettier": "^2.0.5",
    "rollup": "^2.21.0",
    "rollup-plugin-svelte": "^5.2.3",
    "rollup-plugin-terser": "^6.1.0",
    "svelte": "^3.24.0",
    "svelte-check": "^0.1.47",
    "svelte-preprocess": "^4.0.6",
    "tslib": "^2.0.0",
    "typescript": "^3.9.6"
  },
//tsconfig.json
{
    "compilerOptions": {
        "target": "es2017",
        "strict": false, 
        "moduleResolution": "node",
        "allowJs": false,
        "sourceMap": true,
        "lib": [
            "es2017", "DOM"
        ],
        "types": [
            "svelte"
        ],
        "baseUrl": "."
    },
    "include": [
        "src/**/*"
      ],
    "exclude": [
        "node_modules/*", "dist/*"
    ]
}
//rollup.config.js
import svelte from 'rollup-plugin-svelte';
import resolve from '@rollup/plugin-node-resolve';
import {terser} from 'rollup-plugin-terser';
import pkg from './package.json';
import preprocess from 'svelte-preprocess'

...

const production = !process.env.ROLLUP_WATCH;

export default {
	input: 'src/target_lib.ts',
	treeshake: { moduleSideEffects: false },
	output: [
		{ file: pkg.module, 'format': 'es', sourcemap: true },
		{ file: pkg.main, 'format': 'umd', name, sourcemap: true },
	],
	plugins: [
		svelte({
			preprocess: preprocess({
				typescript: {
					transpileOnly: true, 
				}
			})
		}),
		
		resolve({
			browser: true,
			dedupe: ['svelte']
		}),

		...
	]
};

Thanks!

@vatro vatro added the bug Something isn't working label Jul 8, 2020
@vatro vatro changed the title TypeScript Errors ts(2440) with Svelte for VS Code v101.1.1 TypeScript Errors ts(2440) with Svelte for VS Code starting v101.1.0 Jul 8, 2020
@dummdidumm
Copy link
Member

This is a result of a change introduced in #285 , there we changed the transformed tsx output to have named default exports, which are the same as the file. Because of this ts will complain in your Foo.svelte that there are two definitions of Foo now.

As a workaround you can do

Foo.svelte:

<script lang="typescript">
  import { Foo as Foo_ } from './sourcelib';
</script>

This is definitely something we did not consider, maybe we should postfix the converted Components with something that is very unlikely to occur in user's code. Something like export default class Foo_SvelteComponent.

dummdidumm pushed a commit to dummdidumm/language-tools that referenced this issue Jul 9, 2020
Append `__SvelteComponent_` to make it unlikely that name clashes occur.
sveltejs#294
dummdidumm added a commit that referenced this issue Jul 9, 2020
Append `__SvelteComponent_` to make it unlikely that name clashes occur.
#294

Due to this most of the simplifications in #293 had to be reverted.
@dummdidumm dummdidumm added the Fixed Fixed in master branch. Pending production release. label Jul 9, 2020
@vatro
Copy link
Contributor Author

vatro commented Jul 9, 2020

Great! Thank you! ✊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Fixed Fixed in master branch. Pending production release.
Projects
None yet
Development

No branches or pull requests

2 participants