Vscode_deno: @deno-types does not work on first load

Created on 22 Jun 2020  路  10Comments  路  Source: denoland/vscode_deno

postcsstest.ts

import autoprefixer from "https://jspm.dev/autoprefixer";

// @deno-types="./postcss.d.ts"
import postcss from "https://jspm.dev/postcss";

postcss().use(autoprefixer).process(".something { appearance: none; }", {
    from: undefined
}).then((f: any) => {
    console.log(f.css);
})

postcss.d.ts

export default function(): any;

VSCode problem:

image

Notice that it runs correctly, and deno understands the @deno-types just fine, it's just this VSCode extension that doesn't understand these.

Also I think this is the reason for errors elsewhere, e.g. https://github.com/keroxp/servest/issues/133

bug

Most helpful comment

Report current progress

Known issues

On the first load, @deno-types failed to load correctly

You only need to make any changes to trigger a refresh

eg. https://github.com/denoland/vscode_deno/blob/master/examples/compile-hint/mod.ts

1

I have been aware of this problem for a long time, but I鈥檓 not sure if it鈥檚 a bug in typescript or I鈥檓 using it incorrectly.

How @deno-types works in typescript-deno-plugin

In fact, typescript-deno-plugin proxy the typescript method of finding modules.

https://github.com/denoland/vscode_deno/blob/5b379fb995e402ef1fbd808d6f8385ebeca87d62/typescript-deno-plugin/src/plugin.ts#L430-L441

When the import xxx from "xxx" statement is detected, and there is // @deno-types="xxxx" in the previous line of code, it will look for the module specified by deno-types.

And return this path

https://github.com/denoland/vscode_deno/blob/5b379fb995e402ef1fbd808d6f8385ebeca87d62/typescript-deno-plugin/src/plugin.ts#L469-L487

https://github.com/denoland/vscode_deno/blob/5b379fb995e402ef1fbd808d6f8385ebeca87d62/typescript-deno-plugin/src/plugin.ts#L530-L542

But it鈥檚 very strange that it didn鈥檛 take effect the first time it was run, and it only took effect the second.

If someone is good at typescript, please don't be stingy with your help

All 10 comments

I kept thinking something was wrong with my declaration file setup, but I've been running into the same thing (with cheerio instead).

As far as I can tell this might be related to @ry 's recent PR that downgraded the version of the typescript-deno-plugin package being used to before the 1.31.0 version where support for deno-types seems to have been introduced in this PR from @justjavac .

But I haven't found any other discussion around this yet so that might not be an entirely accurate skeleton of a story.

Same problem here:

import jsdom from "https://jspm.dev/jsdom";

const dom = new jsdom.JSDOM("<h1>Hello World!</h1>", { url: "http://localhost "})
console.log(dom.window.document.querySelector("h1").textContent)

The word JSDOM is underlined Property 'JSDOM' does not exist on type '{}'.ts(2339) even though deno accepts it

Might be related as well

// @deno-types="https://denopkg.com/soremwar/deno_types/react/v16.13.1/react.d.ts"
export * from "https://cdn.skypack.dev/react";

Shows no types for either React or its named imports, even though JavaScript can see them just fine when I log them out

Report current progress

Known issues

On the first load, @deno-types failed to load correctly

You only need to make any changes to trigger a refresh

eg. https://github.com/denoland/vscode_deno/blob/master/examples/compile-hint/mod.ts

1

I have been aware of this problem for a long time, but I鈥檓 not sure if it鈥檚 a bug in typescript or I鈥檓 using it incorrectly.

How @deno-types works in typescript-deno-plugin

In fact, typescript-deno-plugin proxy the typescript method of finding modules.

https://github.com/denoland/vscode_deno/blob/5b379fb995e402ef1fbd808d6f8385ebeca87d62/typescript-deno-plugin/src/plugin.ts#L430-L441

When the import xxx from "xxx" statement is detected, and there is // @deno-types="xxxx" in the previous line of code, it will look for the module specified by deno-types.

And return this path

https://github.com/denoland/vscode_deno/blob/5b379fb995e402ef1fbd808d6f8385ebeca87d62/typescript-deno-plugin/src/plugin.ts#L469-L487

https://github.com/denoland/vscode_deno/blob/5b379fb995e402ef1fbd808d6f8385ebeca87d62/typescript-deno-plugin/src/plugin.ts#L530-L542

But it鈥檚 very strange that it didn鈥檛 take effect the first time it was run, and it only took effect the second.

If someone is good at typescript, please don't be stingy with your help

Wow thank you for that awesome workaround @axetroy + the investigation into this.

It also seems to work for me if I open the cached d.ts file in VS Code and then save it without making any changes (and then the red squiggles go away and the intellisense from the typings comes in), but as soon as I close the cached d.ts file the squiggles/lack of intellisense comes back. Not sure if others are seeing that behavior as well (deno 1.1.0, typescript 3.9.2, Deno VS Code extension 2.0.16)

image

first time run the typescript-deno-plugin already give the right result, but tsserver didn't pick it up yet ...until resolveModuleNames retriggered second time

image

really annoying when something should work but didn't

KXgQj81unt

really? Microsoft?

what can I say
lTGP5Llsvj

Resolved in version 3.x of the extension.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dd-pardal picture dd-pardal  路  10Comments

elazutkin-dynata picture elazutkin-dynata  路  8Comments

promethyttrium picture promethyttrium  路  10Comments

evilsquirrel404 picture evilsquirrel404  路  4Comments

zeljkoantich picture zeljkoantich  路  9Comments