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
Change chalk.Level
from const enum
to enum
#373
Conversation
node_modules/chalk/index.d.ts(403,16): error TS2748: Cannot access ambient const enums when the '--isolatedModules' flag is provided.
// @KSXGitHub |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sindresorhus You can merge this.
Is this not a breaking change? |
It's not a breaking change. However, TypeScript wouldn't convert |
So it is breaking, but only for those treating |
would be great if this can get merged, it broke my build after upgrading to latest chalk release |
@fmal Major releases should always be considered breaking. If you choose to update a dependency to a major version, be prepared to make some code changes - not all "breaks" are going to be "fixed" like this one. |
I got problem to use by error TS2748 . |
Is this PR still headed for merge or...? |
Any updates on whether this PR may be merged? |
If anyone wants to see this merged, please open an issue on TypeScript requesting |
@babel/preset-typescript gets about 3.7 million weekly downloads; typescript gets about 7.9 million. This is not a rigorous analysis... but, because the problem arises with
There is a plugin (babel-plugin-const-enum) that can help with the In summary: many TypeScript projects won't be able to use chalk 3.x if it retains I'm sure none of the above will convince you to change your mind, and there's certainly no resentment on my part. I wasn't sure how many people who encounter this issue understand the core of the problem, so I hope my comment is helpful. Thanks for all your hard work on this wonderful library! |
They don't need to remove it, just officially discourage it. |
@michaelsbradleyjr Thanks for elaborating. I think you should just copy-paste your above comment into a TypeScript issue to show the TypeScript maintainers that |
Done. |
@michaelsbradleyjr Thanks :) |
I'm ok with removing the Lines 221 to 231 in 797461e
|
chalk.Level
from const enum
to enum
@sindresorhus I believe it's ok to leave that code as-is. The TypeScript-generated code looks different, but is functionally the same as that object: "use strict";
var LevelEnum;
(function (LevelEnum) {
/**
All colors disabled.
*/
LevelEnum[LevelEnum["None"] = 0] = "None";
/**
Basic 16 colors support.
*/
LevelEnum[LevelEnum["Basic"] = 1] = "Basic";
/**
ANSI 256 colors support.
*/
LevelEnum[LevelEnum["Ansi256"] = 2] = "Ansi256";
/**
Truecolor 16 million colors support.
*/
LevelEnum[LevelEnum["TrueColor"] = 3] = "TrueColor";
})(LevelEnum || (LevelEnum = {})); |
@sindresorhus we're not going to "officially discourage" anyone from using A programmer can write an incorrect TypeScript declaration file using any of our syntax; the author is at fault when this happens, not the specific constructs they used to err with. Why would you block this good PR, which meaningfully improves the experience of users of this library, for the sake of us telling people not to use a construct which has valid use cases? It's befuddling to me. |
This is only the case because it was added as an attempt to fix this exact issue: 4e65299
The docs does not mention that it will not work for half of TS users. A clear disclaimer in the docs about this would be nice.
This PR is only blocked by it being a breaking change and we were not ready to do a major release yet. |
Hmm, now that 4e65299 was merged this might be a moot point, but before that wouldn't it have been more accurate to type When accepting enums, I don't think that the literal values are accepted. So making it an enum makes the JavaScript code read e.g. Maybe I'm missing some good arguments though 🤔 If we are going to do a breaking change we also have to option to switch to a type union and revert 4e65299, if we think that that would be better... |
@LinusU There was a good intention behind this. |
This includes a local patch for `chalk` which is using `const enum`. chalk/chalk#373
Can we get something merged soon to get the typings fixed? |
Fixes #382