Skip to content

A project targeting ES3 that transitively depends on @types/acorn will error on compile #24595

Closed

Description

@laughinghan

Repro steps:

In a clean folder (not inside a repo with a node_modules/ already):

echo 'console.log(`hello world`);' > foo.ts
npm install --no-save @types/acorn
tsc foo.ts

Expected behavior: foo.ts compiles with no problem.

Observed behavior:

node_modules/@types/acorn/index.d.ts(240,8): error TS2304: Cannot find name 'Symbol'.
node_modules/@types/acorn/index.d.ts(240,28): error TS2304: Cannot find name 'Iterator'.

I tried to fix this, but the only thing that seems to make the error go away is:

declare global {
  interface SymbolConstructor {
    readonly iterator: symbol;
  }
  var Symbol: SymbolConstructor;
}

Which leaks Symbol and Symbol.iterator into the global scope for foo.ts, when it shouldn't be available since foo.ts is being compiled to target ES3.

I also tried looking into what other type packages do to fix this, but I only found other type packages that have a similar problem, for example @types/zen-observables:

node_modules/@types/zen-observable/index.d.ts(35,14): error TS2304: Cannot find name 'Symbol'.
node_modules/@types/zen-observable/index.d.ts(46,6): error TS2304: Cannot find name 'Symbol'.

Activity

  1. orta commented on Jun 7, 2021

    @orta
    Collaborator

    Hi thread, we're moving DefinitelyTyped to use GitHub Discussions for conversations the @types modules in DefinitelyTyped.

    To help with the transition, we're closing all issues which haven't had activity in the last 6 months, which includes this issue. If you think closing this issue is a mistake, please pop into the TypeScript Community Discord and mention the issue in the definitely-typed channel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions