https://twitter.com/larymagal/status/1021741263358443520
As a more basic example:
declare function bar(): string
enum E {
foo = bar();
}
Currently we give the error
Type 'string' is not assignable to type 'E'.
However, we should give an error like
Only numeric enums can have computed members, but this expression has type 'string'.
If you do not need exhaustiveness checks, consider using an object literal instead.
A PR would be appreciated.
@mhegazy I can try this?
go for it.
Thanks, can you give me a direction on this?
I need to modify the Error handler message, so how do I move on to identifying the file? Is there a way to produce the error stack?
Will it be the ~\ts\bulit\local\tsc.js line 4775?
Error messages are defined in https://github.com/Microsoft/TypeScript/blob/master/src/compiler/diagnosticMessages.json. you will need to create a new error message, build (jake local), then use the new error message in https://github.com/Microsoft/TypeScript/blob/master/src/compiler/checker.ts
@HarshKhatore are you still pursuing this. If not, then I would like to give it a try.
Can I try this one?
@mhegazy Hi, I try this but I need some help. I create a new error message in diagnosticMessages.json but I don't know wich function in checker I should put the new error message.
Should this error cover this case?:
"Computed_values_are_not_permitted_in_an_enum_with_string_valued_members_2553" : "Computed values are not permitted in an enum with string valued members."
I am trying to figure this out, but man am I starting to feel stupid.
What I know:
computeConstantValue() [26417]bar(): string (in the example) falls through the if-tests and a call is made to checkTypeAssignableTo() which returns an error.How can I find out if member.initializer is a string foo = "hi" or a functon returning a string foo = bar()?
I would love to solve this, but need some help.
Sorry but I didn't notice there's already a PR. Wasted effort. :disappointed:
Hi @DanielRosenwasser , I've one question:
enum Foo {
A = 5
}
enum Bar {
B = Foo.A,
}
Is Bar.B a constant enum member or a computed enum member?
I'm not sure, I think constant but you'd need to check the compiler source.
@DanielRosenwasser
Hi, I submitted the PR https://github.com/microsoft/TypeScript/pull/37790, could you check it?
Most helpful comment
Error messages are defined in https://github.com/Microsoft/TypeScript/blob/master/src/compiler/diagnosticMessages.json. you will need to create a new error message, build (
jake local), then use the new error message in https://github.com/Microsoft/TypeScript/blob/master/src/compiler/checker.ts