denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
93.49k stars 5.18k forks source link

Bug: babel visitor types always cast to `any` #24461

Open marvinhagemeister opened 1 week ago

marvinhagemeister commented 1 week ago

Noticed that the babel visitor types don't work in Deno. They work when using Node though. Spent some time digging into this but couldn't find out why it doesn't work in Deno. Both the LSP and deno check will complain about _nodePath being of type any in Deno. I can cmd+click through the types though and they are all there.

Steps to reproduce

// @deno-types="npm:@types/babel__core"
import * as babel from "npm:@babel/core";

const foo: babel.PluginObj = {
  name: "foo",
  visitor: {
    // The `_nodePath` argument is flagged as "any" in Deno, works in Node with tsc
    Program(_nodePath) {},
  },
};

Version: Deno 1.44.4

marvinhagemeister commented 1 week ago

Ah I think I know what the reason is: Like in the snippet, @babel/core doesn't ship with type definitions and needs @types/babel__core for that. This in turn pulls in @babel/traverse which doesn't ship with type definitions either and would need to fall back to @types/babel__traverse. But we don't seem to be able to do that. Same happens for some other babel modules.

DEBUG TS -   specifiers: @babel/generator, @babel/parser, @babel/template, @babel/traverse, @babel/types, @babel/parser
DEBUG RS - deno::npm::managed:531 - Resolved @babel/generator from file:///Users/marvinh/Library/Caches/deno/npm/registry.npmjs.org/@types/babel__core/7.20.5/index.d.ts to /Users/marvinh/Library/Caches/deno/npm/registry.npmjs.org/@babel/generator/7.24.7
DEBUG RS - deno::tsc:681 - Resolved @babel/generator to ("internal:///missing_dependency.d.ts", ".d.ts")
DEBUG RS - deno::npm::managed:531 - Resolved @babel/parser from file:///Users/marvinh/Library/Caches/deno/npm/registry.npmjs.org/@types/babel__core/7.20.5/index.d.ts to /Users/marvinh/Library/Caches/deno/npm/registry.npmjs.org/@babel/parser/7.24.7
DEBUG RS - deno::tsc:681 - Resolved @babel/parser to ("file:///Users/marvinh/Library/Caches/deno/npm/registry.npmjs.org/@babel/parser/7.24.7/typings/babel-parser.d.ts", ".d.cts")
DEBUG RS - deno::npm::managed:531 - Resolved @babel/template from file:///Users/marvinh/Library/Caches/deno/npm/registry.npmjs.org/@types/babel__core/7.20.5/index.d.ts to /Users/marvinh/Library/Caches/deno/npm/registry.npmjs.org/@babel/template/7.24.7
DEBUG RS - deno::tsc:681 - Resolved @babel/template to ("internal:///missing_dependency.d.ts", ".d.ts")
DEBUG RS - deno::npm::managed:531 - Resolved @babel/traverse from file:///Users/marvinh/Library/Caches/deno/npm/registry.npmjs.org/@types/babel__core/7.20.5/index.d.ts to /Users/marvinh/Library/Caches/deno/npm/registry.npmjs.org/@babel/traverse/7.24.7
DEBUG RS - deno::tsc:681 - Resolved @babel/traverse to ("internal:///missing_dependency.d.ts", ".d.ts")

I guess we need smarter integration with DefinitelyTyped here.