Cannot assign number to "number | undefined" when using package.json
Hi. I'm having odd behavior when using a newly created Vite vanilla TypeScript template using
deno init --npm vite@latest
. Right after initialization I'm installing the game library https://www.npmjs.com/package/excalibur. A game object in the engine is written like this:
but the lsp shows error on the width
and height
properties. It says
Type 'number' is not assignable to type 'undefined'.though they are both a type of
number | undefined
. If I replace the package.json file with a deno.json file and reinstalls the node_modules it all works. I have tested on two machines. Is it a bug or am I missing something?
Here is how I reproduce:
1. Run deno init --npm vite@latest test-exc
, select Vanilla, select TypeScript
2. Run deno install
inside the project.
3. Add the Excalibur dependency with deno add npm:excalibur
4. Replace the contents of main.ts with
5. At this point I have errors on width
and height
.
6. Delete the package.json and create a deno.json file with this content:
6. Fix the import to npm:excalibur
, remove the node_modules folder, and reinstall with deno install
.
7: Errors are gone.2 Replies
Could they be resolving different versions of the
npm:excalibur
library? (Check its version in package-lock.json and deno.lock files)Oh yeah, I didn't check for different versions. I'll give it another shot.
I think they resolved to same version, but now I noticed a warning in the terminal that I might not have payed attention to before:
Warning The following packages contained npm lifecycle scripts (preinstall/install/postinstall) that were not executed: ┠─ npm:core-js@3.36.1 ┃ ┠─ This may cause the packages to not work correctly. ┖─ To run lifecycle scripts, use theI ran the command and now the errors are gone :deno_it_works:--allow-scripts
flag withdeno install
: deno install --allow-scripts=npm:core-js@3.36.1