0

I have a component written in Svelte 5, using $props() rune.

LogActions.svelte

<script lang="ts">
  //@ts-expect-error
  let { onSave }: { (): void } = $props() ;

</script>

<div class="panel fullsize">

  <button onclick={onSave}>Log QSO</button>
  <button>Delete Last</button>
  <button>Undelete</button>
  <button>Edit Last</button>
</div>

<style>
   .fullsize { width: 100% }
</style>

Please note: without the //@ts-expect-error directive, this file causes svelte-check error Error: Property 'onSave' does not exist on type '$$ComponentProps'. (ts)

This component is used in its parent component, EntryPanel.svelte, this way:

<script lang="ts">

  import LogActions from './LogActions.svelte'

  function onSave(): void {
    const content = JSON.stringify(Object.fromEntries(qso))
    console.log(content)
    //@ts-expect-error
    window.api.saveQso( content )
  }

</script>
...
  <LogActions {onSave} />

The last line generates svelte-check error

c:\Users\jvavruska\dev\log73se\src\renderer\src\components\EntryPanel.svelte:41:16
Error: Object literal may only specify known properties, and 'onSave' does not exist in type '$$ComponentProps'. (ts)

  <LogActions {onSave} />
</div>

Unlike the errors in the typescript part, which can be avoided by using //@ts-ignore or //@ts-expect-error, for this error I could not find any directive or hint how to disable the error.

The result is that svelte-check by generating nonsense errors block build of exe file for windows despite that the application works fine in dev mode.

How do I fix this?

1 Answer 1

0

My solution, in the end, is not an actual solution, but it unblocks the build process.

After installing sample electron-svelte scaffolding, there are numerous scripts defined in package.json:

 "scripts": {
    "format": "prettier --plugin prettier-plugin-svelte --write .",
    "lint": "eslint . --ext .js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix",
    "typecheck:node": "tsc --noEmit -p tsconfig.node.json --composite false",
    "svelte-check": "svelte-check --tsconfig tsconfig.json",
    "typecheck": "npm run typecheck:node && npm run svelte-check",
    "start": "electron-vite preview",
    "dev": "electron-vite dev",
    "build": "npm run typecheck && electron-vite build",
    "postinstall": "electron-builder install-app-deps",
    "build:unpack": "npm run build && electron-builder --dir",
    "build:win": "npm run build && electron-builder --win",
    "build:mac": "npm run build && electron-builder --mac",
    "build:linux": "npm run build && electron-builder --linux"
  },

My 'solution' is to simply remove call to svelte-check in the typecheck script:

    "typecheck": "npm run typecheck:node",

After all, svelte-check in this case does not bring any new benefit, as the build process (svelte compiler) reports exactly the same warnings (and errors, should there be any) but does not raise 'fake errors' made up by svelte-check.

As expected, application compiled to *.exe works fine, exactly as does the dev version.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.