Skip to content
This repository has been archived by the owner on Dec 1, 2019. It is now read-only.

bug: hasOwnProperty type guard object patch emits errors on recompile #392

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 94 additions & 0 deletions src/__test__/watch-object-patch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import {
src, webpackConfig, tsconfig,
watch, expectErrors, spec
} from './utils';

spec('just patch Object interface', async function() {
src('index.ts', `
interface Object {
hasOwnProperty<K extends PropertyKey>(k: K): this is {[_ in K]: any }
}

interface TypeA {}
interface TypeB {
bar: boolean;
}

type UnionType = TypeA | TypeB;

const foo: UnionType = {
bar: true
}

if (!foo.hasOwnProperty('bar')) {
throw new Error();
}

foo.bar
`);

tsconfig();

const watcher = watch(webpackConfig());

let stats = await watcher.wait();
expectErrors(stats, 0);
});

spec('patch Object interface and recompile (remove empty line)', async function() {
const index = src('index.ts', `
interface Object {
hasOwnProperty<K extends PropertyKey>(k: K): this is {[_ in K]: any }
}

interface TypeA {}
interface TypeB {
bar: boolean;
}

type UnionType = TypeA | TypeB;

const foo: UnionType = {
bar: true
}

if (!foo.hasOwnProperty('bar')) {
throw new Error();
}

foo.bar
`);

tsconfig();

const watcher = watch(webpackConfig());

let stats = await watcher.wait();
expectErrors(stats, 0);

index.update(() => `
interface Object {
hasOwnProperty<K extends PropertyKey>(k: K): this is {[_ in K]: any }
}

interface TypeA {}
interface TypeB {
bar: boolean;
}

type UnionType = TypeA | TypeB;

const foo: UnionType = {
bar: true
}

if (!foo.hasOwnProperty('bar')) {
throw new Error();
}
foo.bar
`);

stats = await watcher.wait();

expectErrors(stats, 0);
});