tomblachut / svelte-intellij

Svelte components in WebStorm and friends
MIT License
485 stars 38 forks source link

Typescript types no longer resolved from corresponding ".ts" file if import has ".js" extension from 0.21 #240

Closed ghost closed 3 years ago

ghost commented 3 years ago

I have a typescript project setup that does not have a bundle step. Each typescript file is complied by web storm watches when it changes independently. And for the es6 imports to just work out of the box without needing transformations the code imports with ".js" extension instead of ".ts" extension.

Below is an example, where "webgpu.js" is imported instead of "webgpu.ts". image

Typescript compiler seems to handle this properly as well as typescript files inside web storm. And it used to work in svelte files before I updated web storm 2021.2 and before version 0.21 of the plugin. It no longer works as can be seen in the screenshot. Not sure if it's an issue with changes in web storm 2021.2 or with version 0.21 of the plugin

tomblachut commented 3 years ago

Hello. Do I understand correctly, that you haven't used WebStrom 2021.2 with Svelte 0.20.0 (previous version)?

Not sure if it's an issue with changes in web storm 2021.2 or with version 0.21 of the plugin

Please put everything from script tag into separate .ts file, uncheck TypeScript language service and see if something is different. image

If there's still issue please provide small repro project.

ghost commented 3 years ago

@tomblachut

Unfortunately not, as I clicked upgrade plugins, as there was a bunch of plugins that I was that needed upgrade to work with 2021.2.

Well, putting everything in another ".ts" file also only works in svelte files if imported as ".ts" instead of ".js".

I will setup a small repro project

tomblachut commented 3 years ago

Well, putting everything in another ".ts" file also only works in svelte files if imported as ".ts" instead of ".js".

Not sure I understand, can you rephrase? This is a problem in Svelte plugin if the result is different in plain TS file, most problems are inherited by script tags inside Svelte files.

ghost commented 3 years ago

well, it would be more clear once I can show you the small project to repro. I found something interesting about it, creating the project now. Here are the components in raw form that i will put in the minimal repro project

App.svelte

<script lang="ts">
    import {Logger} from "./Logger.js";
    import Ok from "./Ok.svelte";
    import NotOk from "./NotOk.svelte";
    const logger = new Logger();
</script>

<Ok logger/>
<NotOk logger/>

Ok.svelte

<script lang="ts">
    import {Logger} from "./Logger.ts";
    import {onMount} from "../node_modules/svelte/index.mjs";

    export let logger: Logger;

    onMount(() => {
        logger.log('NotOk Component')
    })
</script>

NotOk.svelte

<script lang="ts">
    import {Logger} from "./Logger.js";
    import {onMount} from "../node_modules/svelte/index.mjs";

    export let logger: Logger;

    onMount(() => {
        logger.log('NotOk Component')
    })
</script>

Logger.ts

export class Logger {
    log(msg: string) {
        console.log(msg)
    }
}

Before tsc watcher compiler Logger.ts to Logger.js everything works fine, once transpiledLogger.js is there, NotOK.Svelte complains that logger.log cannot be resolved. image

ghost commented 3 years ago

@tomblachut find the repo with minimal repro here https://github.com/jiby-gh/svelte-intellij-issue-240.

If you just clone the file and open src/NotOk.svelte, it considers types properly, if you then do npm install which compiled src/Logger.ts to generate src/Logger.js, then src/NotOk.svelte will complain about logger.log.

Let me know if you are able to repro.

tomblachut commented 3 years ago

@jiby-gh Ok I see, log is unresolved. When I copy all contents of script tag to standalone TS, problem is exactly the same, therefore this is not a problem with Svelte. I can also confirm that is indeed worked in 2021.1.

image

Please open separate issue in YouTrack.

ghost commented 3 years ago

@tomblachut sorry to bug you again, but that's quite weird, as in my case it does not complain inside standalone TS, very weird. image

ghost commented 3 years ago

interesting that it does not complain for you that type definitions are missing for ../node_modules/svelte/index.mjs which i think it should have

ghost commented 3 years ago

@tomblachut Okay, I just tried with the typescript language service disabled, and it complains in both.

But is it unexpected behaviour, isn't the types in ts provided by the typescript language service, is it supposed to work without the typescript language service?

ghost commented 3 years ago

@tomblachut unfortunately I can confirm that it does not happen with 0.20 of the plugin and web storm 2021.2. I just installed the old version from disk and tried. It works with that combo. So i think it has something to do with the changes in 0.21

image

tomblachut commented 3 years ago

Oh, that's because 0.21 also fixes tsconfig resolution, so in 0.20 case bug was hidden by another one. Your problem still can't be fixed here, only upstream.

as for your question what does ts service do actually, it's really complicated and I can't answer this throughoutly. Types are evaluated in two places basically

ghost commented 3 years ago

ah, okay, thanks for the clarification !