Skip to content

Default lib values don't work with the programmatic TS API #54

@tylerlaprade

Description

@tylerlaprade

Hey! I ran into an issue with the default compilerOptions.lib values in expressive-code-twoslash.

The defaults are set to:

lib: ["Bundler", "ES2022", "DOM", "DOM.Iterable"]

But the TypeScript programmatic API (used by @typescript/vfs under the hood) needs the file path format for lib names — e.g. "lib.es2022.d.ts", "lib.dom.d.ts", etc. The friendly names like "ES2022" and "DOM" only work in tsconfig.json because tsc normalizes them internally before calling the compiler API.

Since twoslash goes through the programmatic API directly, these values are silently ignored, which means DOM types (and ES2022 types) aren't actually loaded by default. I only noticed because code blocks using DOM APIs were getting type errors.

Also, "Bundler" isn't a valid lib name at all — it's a moduleResolution value.

The fix on my end was overriding lib in the config:

ecTwoSlash({
  twoslashOptions: {
    compilerOptions: {
      lib: ["lib.esnext.full.d.ts"],
    },
  },
})

But it'd be nice to have the defaults just work. The correct values would be something like:

lib: ["lib.es2022.d.ts", "lib.dom.d.ts", "lib.dom.iterable.d.ts"]

Thanks for the great plugin!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtwoslashexpressive-code-twoslash

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions