3 ms·
Vanilla VSCode also has surprisingly good code inference for Javascript/Typescript. Recently, Typescript was complaining about an implicit `any` even though th
by hombre_fatal 7y ago
Vanilla VSCode also has surprisingly good code inference for Javascript/Typescript.
Recently, Typescript was complaining about an implicit `any` even though the VSCode tooltip clearly could infer the actual type (it confusingly was showing both cases in the tooltip). I finally realized that VSCode's built-in inference worked here but Typescript didn't work at all because I forgot I was importing a .js file rather than a .ts file.
VSCode for course also downloads @types/* files in the background even in vanilla JS projects which is super helpful because you get effortless intellisense. That it does this kind of stuff out of the box is the sort of reason why I've lost my Vim/Emacs fanaticism over the years.
- DanRosenwasser 7y agoVS Code's JS support is actually still powered by TypeScript. I'm not 100% sure exactly what you were experiencing, but it's intentional that VS and VS Code automatically download types when powering JavaScript contexts because we try to make things "just work" for JS users.
- hombre_fatal 7y agoI don't think you are saying anything in conflict with me. VSCode tries to give you type info in contexts where Typescript wouldn't (e.g. importing Javascript files, in a completely non-TS project) so it makes sense that its inference tooltip can be more helpful. You can easily recreate this by importing a fn from a JS module and then hovering it in VSCode (also configured for Typescript): VSCode knows the fn signature but Typescript won't. Both cases show up in the tooltip (though confusingly). At least, that's my interpretation of this sort of tooltip: https://i.imgur.com/lXS5teK.png https://i.imgur.com/lXS5teK.png And to be clear, your last sentence was my exact praise for VSCode at the end of my own comment.
- tomnipotent 7y ago> intentional that VS and VS Code automatically download types Are these coming from DefinitelyTyped?
- WorldMaker 7y agoIndirectly, sometimes. They come from npm, but the largest chunk of type packages for libraries that do not provide their own types on npm are serviced from DefinitelyTyped (via the `@types` organization and its long tail of shadow packages).
- emilecantin 7y agoYou can get a lot of this nice behaviours in Vim with coc.nvim (if you can get past the awful name). It uses VSCode's language server behind the scenes to offer similar auto-complete / tooltips. It doesn't auto-download @types, but it does suggest them to you. It can also auto-import, rename across files, etc.