Skip to content

export const function is declared but its value is never read #2717

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

Open
Jojoshua opened this issue Mar 18, 2025 · 4 comments
Open

export const function is declared but its value is never read #2717

Jojoshua opened this issue Mar 18, 2025 · 4 comments
Labels
bug Something isn't working Fixed Fixed in master branch. Pending production release.

Comments

@Jojoshua
Copy link
Contributor

Jojoshua commented Mar 18, 2025

Describe the bug

I've highlighted the important parts to explain the issue but basically trying to add type definition to an exported const function throws a ts error. This is similar to #2268 but doesn't involve bindings.
 
Image

Reproduction

app.ts


export type CommonFunction = () => void;

App.svelte

<script lang="ts">
    import type { CommonFunction } from "$lib/app";

    export interface Props {
      name?: string;
    }

    let { name = "world" }: Props = $props();

    export const MyFunction2: CommonFunction = () =>{
      console.log("Hello from MyFunction!");
    }

  </script>

Expected behaviour

No errors are thrown for any exports

System Info

  • OS: [e.g. Windows]
  • IDE: [e.g. VSCode, Atom]

Which package is the issue about?

No response

Additional Information, eg. Screenshots

Note adding //@ts-ignore silences the error, everything does work but would rather not ignore all these errors

@Jojoshua Jojoshua added the bug Something isn't working label Mar 18, 2025
dummdidumm added a commit that referenced this issue Mar 19, 2025
Ensure they are read as part of exporting the types

#2717
@dummdidumm dummdidumm added the Fixed Fixed in master branch. Pending production release. label Mar 19, 2025
dummdidumm added a commit that referenced this issue Mar 19, 2025
Ensure they are read as part of exporting the types

#2717
@jasonlyu123
Copy link
Member

jasonlyu123 commented Apr 13, 2025

Seems like this specific situation is still not fixed but it should work now when there is no explict type annotation.

@jasonlyu123 jasonlyu123 removed the Fixed Fixed in master branch. Pending production release. label Apr 13, 2025
@Jojoshua
Copy link
Contributor Author

Seems like this specific situation is still not fixed but it should work now when there is no explict type annotation.

You're right, we tested svelte check 4.1.6 and still getting the error. The type definition is important to have. Can you just mark anything with export as something to ignore?

@jasonlyu123
Copy link
Member

jasonlyu123 commented Apr 15, 2025

@dummdidumm Did you remember why export const with type annotation is omitted here?

`, exports: {${this.createReturnElements(this.usesRunes() ? others : [], false, true)}} as any as { ` +

If I understand correctly, this is the reason why only the typed export const is unused. But not really sure what the intention is here.

@dummdidumm
Copy link
Member

uuuh I think I wanted to have it the other way around - i.e. only those that don't have a type are omitted. The reasoning was that those without a type are referenced as typeof theExportedConst in the type that follows, which means they are used. Those with a type referenced via their type, so they need to be referenced somehow else, which my PR attempted to do (but failed because I switched it up)

@dummdidumm dummdidumm added the Fixed Fixed in master branch. Pending production release. label Apr 25, 2025
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

3 participants