Incorrect handing `in` operator with string literal
timocov opened this issue · comments
Evgeniy Timokhov commented
Bug report
Input code
export interface ExportedInterface {
foo: number;
}
export interface AnotherExportedInterface {
bar: number;
isAnother: boolean;
}
export type ExportedType = ExportedInterface | AnotherExportedInterface;
interface NonExportedInterface {
foo: number;
}
interface AnotherNonExportedInterface {
bar: number;
isAnother: boolean;
}
type NonExportedType = NonExportedInterface | AnotherNonExportedInterface;
declare function getNonExported(): NonExportedType;
declare const moveEvent: MouseEvent | TouchEvent;
export function func(type: ExportedType): void {
if ('isAnother' in type) {
console.log(type.bar);
} else {
console.log(type.foo);
}
const nonExportedVar = getNonExported();
if ('isAnother' in nonExportedVar) {
console.log(nonExportedVar.bar);
} else {
console.log(nonExportedVar.foo);
}
if ('onorientationchange' in window || 'button' in moveEvent) {
console.log('check');
}
}
Expected output
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function func(type) {
if ('isAnother' in type) {
console.log(type.bar);
}
else {
console.log(type.foo);
}
var nonExportedVar = getNonExported();
if ('_internal_isAnother' in nonExportedVar) {
console.log(nonExportedVar._internal_bar);
}
else {
console.log(nonExportedVar._internal_foo);
}
if ('onorientationchange' in window || 'button' in moveEvent) {
console.log('check');
}
}
exports.func = func;
Actual output
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function func(type) {
if ('isAnother' in type) {
console.log(type.bar);
}
else {
console.log(type.foo);
}
var nonExportedVar = getNonExported();
if ('isAnother' in nonExportedVar) {
console.log(nonExportedVar._internal_bar);
}
else {
console.log(nonExportedVar._internal_foo);
}
if ('onorientationchange' in window || 'button' in moveEvent) {
console.log('check');
}
}
exports.func = func;