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

Conversation

fahrradflucht
Copy link

This PR is just a failing test to demonstrate the bug
We want to use hasOwnProperty as a type guard so we patched Object like this:

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

This makes code like this valid:

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

type UnionType = TypeA | TypeB;
const foo: UnionType = {
  bar: true
}

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

foo.bar

The problem we have is that awesome-typescript-loader (and ts-loader) emits errors as if it didn't saw the Object patch but only on recompile in watch-mode.

I wrote two tests, one that succeeds without a problem because it just compiles the code once (which demonstrates that this is a watch mode issue) and one that fails despite the fact that the only change that is made between the first compile and the incremental build is a whitespace change.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant