You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Destructing assignment fail to implicit cast type #26804
enumKind{Square="square",Rectangle="rectangle"}typeShape=|{kind: Kind.Square;size: number;}|{kind: Kind.Rectangle;width: number;height: number;};functionarea(s: Shape){switch(s.kind){caseKind.Square: {letb=s.size*s.size;break;}default: {letb=s.width*s.height;break;}}}functionarea2(s: Shape){const{ kind }=s;switch(kind){caseKind.Square: {// [ts]// Property 'width' does not exist on type 'Shape'.// Property 'width' does not exist on type '{ kind: Kind.Square; size: number; }'.letb=s.size*s.size;break;}default: {// [ts]// Property 'width' does not exist on type 'Shape'.// Property 'width' does not exist on type '{ kind: Kind.Square; size: number; }'.letb=s.width*s.height;break;}}}
Expected behavior:
No error
Actual behavior:
test.ts(34,19): error TS2339: Property 'size' does not exist on type 'Shape'.
Property 'size' does not exist on type '{ kind: Kind.Rectangle; width: number; height: number; }'.
test.ts(34,28): error TS2339: Property 'size' does not exist on type 'Shape'.
Property 'size' does not exist on type '{ kind: Kind.Rectangle; width: number; height: number; }'.
test.ts(38,19): error TS2339: Property 'width' does not exist on type 'Shape'.
Property 'width' does not exist on type '{ kind: Kind.Square; size: number; }'.
test.ts(38,29): error TS2339: Property 'height' does not exist on type 'Shape'.
Property 'height' does not exist on type '{ kind: Kind.Square; size: number; }'.
Activity
RyanCavanaugh commentedon Aug 31, 2018
Duplicate of #12184
const#12184