Open itsdouges opened 1 year ago
Sorry, what I'm about to say wasn't in the manual until today. You can make this work by adding a @deno-types
above the import to tell Deno where to get the types (you might want to map the @types
package in an import map):
// @deno-types="npm:@types/three@0.144.0"
import { Box3, Layers, PerspectiveCamera as PC, Vector3, Vector3Tuple } from 'three';
If it gets annoying to add a @deno-types
above each entry, then you can create a module that re-exports the module with the types applied to it (or just put this in a deps.ts file):
// deps/three.ts
// @deno-types="npm:@types/three@0.1440"
export * from "npm:three@0.144.0";
Then update your import map like so:
{
"imports": {
// etc...
"three": "./deps/three.ts"
}
}
That said, I'm confused about why deno check
errors in your original example. It should consider all the named imports as any
types when the npm package doesn't have any types.
I changed the title and marked this as a bug because those original named imports shouldn't have be erroring when running deno check
.
Sorry, what I'm about to say wasn't in the manual until today. You can make this work by adding a
@deno-types
above the import to tell Deno where to get the types (you might want to map the@types
package in an import map):// @deno-types="npm:@types/three@0.144.0" import { Box3, Layers, PerspectiveCamera as PC, Vector3, Vector3Tuple } from 'three';
If it gets annoying to add a
@deno-types
above each entry, then you can create a module that re-exports the module with the types applied to it (or just put this in a deps.ts file):// deps/three.ts // @deno-types="npm:@types/three@0.1440" export * from "npm:three@0.144.0";
Then update your import map like so:
{ "imports": { // etc... "three": "./deps/three.ts" } }
That said, I'm confused about why
deno check
errors in your original example. It should consider all the named imports asany
types when the npm package doesn't have any types.
I'm curious how would be this for React? Currently I'm getting this error:
Hmmm... I feel like that should just work considering it works at runtime in Node and export =
matches the runtime code. I'm going to open or look to see if there's an existing typescript bug. I'll report back in a bit.
As a workaround, you'd have to do either:
import React from "npm:react";
export default React;
...then import and use React
, or re-export each named import individually, which will get annoying:
// @deno-types="npm:@types/react"
import React, { useState, useCallback } from "npm:react";
export default React;
export { useState, useCallback }; // etc...
Thanks @dsherret
Hi! As mentioned in https://github.com/denoland/deno/issues/15960 I'm opening a new issue to talk about this issue I'm having.
Is the task "[ ] automatic acquisition of @types package for type checking" related to type checking npm specifier imports? I'm getting errors such as:
It type checks fine in VSCode, just not with
deno check
. Is there anything on my end to do for a fix?My deno.json:
My import_map.json: