Skip to content

problem with type-only imports for typescript #1092

Closed
@betfix

Description

@betfix

I noticed a problem with syntax highlighting, auto-import, svelte-check and Quick Fix options for importing Typescript types.

E.g. for this code

<script lang="ts">
import { Link } from 'svelte-navigator'
export let navigate: NavigateFn
</script> 
  1. auto-import
    During typing the word "NavigateFn" intellisense displays a tooltip to auto-import this type from svelte-navigator. The auto-import adds the type to existing import, resulting in:
    import { Link, NavigateFn } from 'svelte-navigator'

  2. Quick Fix
    The same happens when choosing a Quick Fix option to add NavigateFn to existing import (this is the only option to choose).

  3. syntax highlighting
    All is looking ok inside VSCode, despite adding a compiler option in tsconfig.json:
    "importsNotUsedAsValues": "error"
    Setting this option to "remove" or "preserve" seems to have no impact on VSCode behavior, either.

  4. svelte-check
    No error

During runtime there is an error:

SyntaxError: The requested module '/node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/svelte-navigator/src/index.js' does not provide an export named 'NavigateFn'

The expected behavior is to:

  1. either display an error inside VSCode and in svelte-check, according to the "importsNotUsedAsValues": "error" typescript setting

  2. or make auto-import and Quick Fix use type-only import for types, resulting in code:

import { Link } from 'svelte-navigator'
import type { NavigateFn } from 'svelte-navigator'

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions