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

LevelEnum type error; Cannot access ambient const enums with --isolatedModules #382

Closed
maxmilton opened this issue Feb 2, 2020 · 2 comments

Comments

@maxmilton
Copy link

maxmilton commented Feb 2, 2020

  • Operating System (or Browser): Arch Linux
  • chalk Version: 3.0.0
  • Node Version: 13.7.0
  • TypeScript Version: 3.7.5

How Do We Reproduce?

  1. Import chalk in a TypeScript project
  2. Attempt to build the project with the --isolatedModules option

See minimal repro: https://github.com/MaxMilton/repro-chalk-enum-type

Expected Behaviour

Project builds without type errors.

Actual Behaviour

Type error is thrown due to ambient const enums not supported with the --isolatedModules option.

❯ yarn run build
yarn run v1.21.1
$ tsc --isolatedModules --esModuleInterop index.ts
node_modules/chalk/index.d.ts:403:16 - error TS2748: Cannot access ambient const enums when the '--isolatedModules' flag is provided.

403  Level: typeof LevelEnum;
                   ~~~~~~~~~


Found 1 error.

error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Changing chalk/index.d.ts from...

declare const enum LevelEnum {

... to...

declare enum LevelEnum {

... resolves the issue. Since chalk.Level is already defined in the source, this change shouldn't impact consumer functionality.

There is a similar issue #363 which took a step towards fixing this but didn't quite get all the way there.

Developers upgrading to Jest v25.1.0 packages are going to run into this.

@viceice
Copy link

viceice commented Feb 5, 2020

Seeing this too

@maxmilton
Copy link
Author

Thank you for switching to a union 🎉 🎉

I've been patching chalk across all projects I touch so very much looking forward to using the stock standard types!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants