sveltejs/sapper

Error: @rollup/plugin-typescript TS2345: Argument of type 'X' is not assignable to parameter of type 'Y<X>'

Closed this issue · 1 comments

Describe the bug
Passing type X to a function with parameter of type Y causes Error TS2345 when using Svelte and/or Sapper. All works fine when not using Svelte/Sapper.

Created 2 repos:

  1. https://github.com/regnaio/issue (has TS2345 error)
    Steps:
  • git clone https://github.com/regnaio/issue.git
  • cd issue
  • npm i
  • Observe that the file /src/ts/skybox/Skybox.ts has lint showing a compilation error
  • npm run export (yields TS2345 error)
  1. https://github.com/regnaio/works (works fine)
    Steps:
  • git clone https://github.com/regnaio/works.git
  • Observe that the file /ts/skybox/Skybox.ts has lint showing no compilation errors

Image of error in https://github.com/regnaio/issue:
Screenshot (1266)

Logs

$ npm run host

> Issue@0.0.1 host C:\dev\issue
> npm run clean && npm run export && npx serve __sapper__/export -p 80


> Issue@0.0.1 clean C:\dev\issue
> rm -rf ./__sapper__


> Issue@0.0.1 export C:\dev\issue
> sapper export --legacy

> Building...

[!] (plugin typescript) Error: @rollup/plugin-typescript TS2345: Argument of type 'Mesh' is not assignable to parameter of type 'DeepImmutableObject<AbstractMesh>'.
  The types of '_internalAbstractMeshDataInfo._skeleton' are incompatible between these types.
    Type 'Nullable<Skeleton>' is not assignable to type 'DeepImmutableObject<Skeleton> | null'.
      Type 'Skeleton' is not assignable to type 'DeepImmutableObject<Skeleton>'.
        The types of 'bones.concat' are incompatible between these types.
          Type '{ (...items: ConcatArray<Bone>[]): Bone[]; (...items: (Bone | ConcatArray<Bone>)[]): Bone[]; }' is not assignable to type '{ (...items: ConcatArray<DeepImmutableObject<Bone>>[]): DeepImmutableObject<Bone>[]; (...items: (DeepImmutableObject<Bone> | ConcatArray<...>)[]): DeepImmutableObject<...>[]; }'.
            Types of parameters 'items' and 'items' are incompatible.
              Type 'ConcatArray<DeepImmutableObject<Bone>>' is not assignable to type 'ConcatArray<Bone>'.
                Type 'DeepImmutableObject<Bone>' is missing the following properties from type 'Bone': _skeleton, _localMatrix, _restPose, _bindPose, and 29 more.
C:/dev/issue/src/ts/skybox/Skybox.ts (23:24)
e following properties from type 'Bone': _skeleton, _localMatrix, _restPose, _bindPose, and 29 more.

23     ray.intersectsMesh(mesh, false);
                          ~~~~

Error: @rollup/plugin-typescript TS2345: Argument of type 'Mesh' is not assignable to parameter of type 'DeepImmutableObject<AbstractMesh>'.
  The types of '_internalAbstractMeshDataInfo._skeleton' are incompatible between these types.
    Type 'Nullable<Skeleton>' is not assignable to type 'DeepImmutableObject<Skeleton> | null'.
      Type 'Skeleton' is not assignable to type 'DeepImmutableObject<Skeleton>'.
        The types of 'bones.concat' are incompatible between these types.
          Type '{ (...items: ConcatArray<Bone>[]): Bone[]; (...items: (Bone | ConcatArray<Bone>)[]): Bone[]; }' is not assignable to type '{ (...items: ConcatArray<DeepImmutableObject<Bone>>[]): DeepImmutableObject<Bone>[]; (...items: (DeepImmutableObject<Bone> | ConcatArray<...>)[]): DeepImmutableObject<...>[]; }'.
            Types of parameters 'items' and 'items' are incompatible.
              Type 'ConcatArray<DeepImmutableObject<Bone>>' is not assignable to type 'ConcatArray<Bone>'.
                Type 'DeepImmutableObject<Bone>' is missing the following properties from type 'Bone': _skeleton, _localMatrix, _restPose, _bindPose, and 29 more.
    at error (C:\dev\issue\node_modules\rollup\dist\shared\rollup.js:5195:30)
    at throwPluginError (C:\dev\issue\node_modules\rollup\dist\shared\rollup.js:17702:12)
    at Object.error (C:\dev\issue\node_modules\rollup\dist\shared\rollup.js:18321:24)
    at emitDiagnostic (C:\dev\issue\node_modules\@rollup\plugin-typescript\dist\index.js:415:17)
    at reportDiagnostics (C:\dev\issue\node_modules\@rollup\plugin-typescript\dist\index.js:423:9)
    at Array.forEach (<anonymous>)
    at emitFilesAndReportErrors (C:\dev\issue\node_modules\typescript\lib\typescript.js:105333:21)
    at Object.result.afterProgramCreate (C:\dev\issue\node_modules\typescript\lib\typescript.js:105503:13)
    at Object.afterProgramCreate (C:\dev\issue\node_modules\@rollup\plugin-typescript\dist\index.js:515:29)
    at synchronizeProgram (C:\dev\issue\node_modules\typescript\lib\typescript.js:105767:22)

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! Issue@0.0.1 export: `sapper export --legacy`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the Issue@0.0.1 export script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\georg\AppData\Roaming\npm-cache\_logs\2020-08-18T06_43_48_549Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! Issue@0.0.1 host: `npm run clean && npm run export && npx serve __sapper__/export -p 80`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the Issue@0.0.1 host script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\georg\AppData\Roaming\npm-cache\_logs\2020-08-18T06_43_48_574Z-debug.log

To Reproduce
Please make sure you've tested with the latest versions of Svelte and Sapper.

To help us help you, if you've found a bug please consider the following:

  • If possible, we recommend creating a small repo that illustrates the problem.
  • Reproductions should be small, self-contained, correct examples – http://sscce.org.

Occasionally, this won't be possible, and that's fine – we still appreciate you raising the issue. But please understand that Svelte is run by unpaid volunteers in their free time, and issues that follow these instructions will get fixed faster.

Expected behavior
A clear and concise description of what you expected to happen.

Stacktraces
If you have a stack trace to include, we recommend putting inside a <details> block for the sake of the thread's readability:

Stack trace

Stack trace goes here...

Information about your Sapper Installation:

  • The output of npx envinfo --system --npmPackages svelte,sapper,rollup,webpack --binaries --browsers:
$ npx envinfo --system --npmPackages svelte,sapper,rollup,webpack --binaries --browsers
npx: installed 1 in 1.344s

  System:
    OS: Windows 10 10.0.18362
    CPU: (8) x64 Intel(R) Core(TM) i7-7820HQ CPU @ 2.90GHz
    Memory: 19.55 GB / 31.82 GB
  Binaries:
    Node: 14.8.0 - C:\Program Files\nodejs\node.EXE
    npm: 6.14.7 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Chrome: 84.0.4147.125
    Edge: Spartan (44.18362.449.0)
    Internet Explorer: 11.0.18362.1
  npmPackages:
    rollup: ^2.3.4 => 2.25.0
    sapper: ^0.28.0 => 0.28.0
    svelte: ^3.17.3 => 3.24.1
$ tsc -v
Version 3.9.7

$ npm -v
6.14.7

$ node -v
v14.8.0
  • Your browser: Google Chrome, but not too relevant in this case

  • Your hosting environment (i.e. Local, GCP/AWS/Azure, Vercel/Begin, etc...): Local

  • If it is an exported (npm run export) or dynamic application: Used npm run export and npm run dev

Severity
A workaround is using lengthy casts, e.g. mesh as BABYLON.DeepImmutableObject<BABYLON.Mesh> instead of just mesh. Similar lengthy casts may need to be done with many of BABYLON's functions.

Additional context
Add any other context about the problem here.

I might be missing something, but this doesn't look at all related to Sapper, but looks like just a general TypeScript usage issue. This really isn't the right place for that type of question and I'm not sure I'd be the right person to help with it anyway. Trying finding some TypeScript related forum or chat or ask on StackOverflow