TypeScript Version: 3.9.2
Search Terms:
Expected behavior:
It would be great to check if all enum values are exclusively overlap, and only throw error when it is not.
Actual behavior:
Now it shows error even when they have exactly same values:
Conversion of type 'EnumA' to type 'EnumB' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.(2352)
Related Issues:
Code
export enum EnumA {
Key = 'VALUE',
}
export enum EnumB {
Key = 'VALUE',
}
function assign(val: EnumA) {
const val2: EnumB = val as EnumB; // <--- getting error here
return val2;
}
Output
export var EnumA;
(function (EnumA) {
EnumA["Key"] = "VALUE";
})(EnumA || (EnumA = {}));
export var EnumB;
(function (EnumB) {
EnumB["Key"] = "VALUE";
})(EnumB || (EnumB = {}));
function assign(val) {
const val2 = val;
return val2;
}
Compiler Options
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"strictPropertyInitialization": true,
"strictBindCallApply": true,
"noImplicitThis": true,
"noImplicitReturns": true,
"useDefineForClassFields": false,
"alwaysStrict": true,
"allowUnreachableCode": false,
"allowUnusedLabels": false,
"downlevelIteration": false,
"noEmitHelpers": false,
"noLib": false,
"noStrictGenericChecks": false,
"noUnusedLocals": false,
"noUnusedParameters": false,
"esModuleInterop": true,
"preserveConstEnums": false,
"removeComments": false,
"skipLibCheck": false,
"checkJs": false,
"allowJs": false,
"declaration": true,
"experimentalDecorators": false,
"emitDecoratorMetadata": false,
"target": "ES2017",
"module": "ESNext"
}
}
Playground Link: Provided
TypeScript Version: 3.9.2
Search Terms:
Expected behavior:
It would be great to check if all enum values are exclusively overlap, and only throw error when it is not.
Actual behavior:
Now it shows error even when they have exactly same values:
Related Issues:
Code
Output
Compiler Options
{ "compilerOptions": { "noImplicitAny": true, "strictNullChecks": true, "strictFunctionTypes": true, "strictPropertyInitialization": true, "strictBindCallApply": true, "noImplicitThis": true, "noImplicitReturns": true, "useDefineForClassFields": false, "alwaysStrict": true, "allowUnreachableCode": false, "allowUnusedLabels": false, "downlevelIteration": false, "noEmitHelpers": false, "noLib": false, "noStrictGenericChecks": false, "noUnusedLocals": false, "noUnusedParameters": false, "esModuleInterop": true, "preserveConstEnums": false, "removeComments": false, "skipLibCheck": false, "checkJs": false, "allowJs": false, "declaration": true, "experimentalDecorators": false, "emitDecoratorMetadata": false, "target": "ES2017", "module": "ESNext" } }Playground Link: Provided