Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@deno-types does not work on first load #97

Closed
Ciantic opened this issue Jun 21, 2020 · 10 comments
Closed

@deno-types does not work on first load #97

Ciantic opened this issue Jun 21, 2020 · 10 comments
Labels
bug Something isn't working

Comments

@Ciantic
Copy link

Ciantic commented Jun 21, 2020

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. keroxp/servest#133

@Grunet
Copy link

Grunet commented Jun 22, 2020

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.

@HoffmannP
Copy link

HoffmannP commented Jul 20, 2020

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

@bartlomieju bartlomieju added the bug Something isn't working label Aug 4, 2020
@Soremwar
Copy link

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

@axetroy
Copy link
Contributor

axetroy commented Aug 30, 2020

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’m not sure if it’s a bug in typescript or I’m using it incorrectly.

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

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

languageServiceHost.resolveModuleNames = (
moduleNames: string[],
containingFile: string,
...rest
): (
| ts_module.ResolvedModule
| ts_module.ResolvedModuleFull
| undefined
)[] => {
if (!this.configurationManager.config.enable) {
return resolveModuleNames(moduleNames, containingFile, ...rest);
}

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

// handle @deno-types
if (content && content.indexOf("// @deno-types=") >= 0) {
const sourceFile = this.typescript.createSourceFile(
containingFile,
content,
this.typescript.ScriptTarget.ESNext,
true
);
const modules = getImportModules(this.typescript)(sourceFile);
for (const m of modules) {
if (m.hint) {
const index = moduleNames.findIndex((v) => v === m.moduleName);
moduleNames[index] = m.hint.text;
}
}
}

return resolvedModules.map((v) => {
if (!v) {
return v;
}
const result: ts_module.ResolvedModuleFull = {
extension: v.extension as ts_module.Extension,
isExternalLibraryImport: false,
resolvedFileName: v.filepath,
};
return result;
});

But it’s very strange that it didn’t 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

@Grunet
Copy link

Grunet commented Aug 30, 2020

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)

@lucacasonato lucacasonato changed the title @deno-types does not work @deno-types does not work on first load Sep 8, 2020
@lucacasonato lucacasonato mentioned this issue Sep 8, 2020
10 tasks
@CGQAQ
Copy link
Contributor

CGQAQ commented Sep 30, 2020

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

@CGQAQ
Copy link
Contributor

CGQAQ commented Sep 30, 2020

image

really annoying when something should work but didn't

@CGQAQ
Copy link
Contributor

CGQAQ commented Sep 30, 2020

KXgQj81unt

really? Microsoft?

@CGQAQ
Copy link
Contributor

CGQAQ commented Sep 30, 2020

what can I say
lTGP5Llsvj

@lucacasonato
Copy link
Member

Resolved in version 3.x of the extension.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

8 participants