TypeScript/tests/baselines/reference/typeGuardsWithInstanceOf.errors.txt
Orta Therox 8c5fa5cc91
Revert assignability cases in getNarrowedType (#42231)
* Revert subtype narrowing changes from readonly array PRs

* Adds a test for the change

* More baselines
2021-02-09 15:03:11 -08:00

59 lines
2.5 KiB
Plaintext

tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOf.ts(7,20): error TS2339: Property 'global' does not exist on type 'never'.
The intersection 'I & RegExp' was reduced to 'never' because property 'global' has conflicting types in some constituents.
tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOf.ts(36,11): error TS2339: Property 'onChanges' does not exist on type 'C | (Validator & Partial<OnChanges>)'.
Property 'onChanges' does not exist on type 'C'.
tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOf.ts(37,11): error TS2339: Property 'onChanges' does not exist on type 'C | (Validator & Partial<OnChanges>)'.
Property 'onChanges' does not exist on type 'C'.
==== tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOf.ts (3 errors) ====
interface I { global: string; }
var result!: I;
var result2!: I;
if (!(result instanceof RegExp)) {
result = result2;
} else if (!result.global) {
~~~~~~
!!! error TS2339: Property 'global' does not exist on type 'never'.
!!! error TS2339: The intersection 'I & RegExp' was reduced to 'never' because property 'global' has conflicting types in some constituents.
}
// Repro from #31155
interface OnChanges {
onChanges(changes: Record<string, unknown>): void
}
interface Validator {
validate(): null | Record<string, unknown>;
}
class C {
validate() {
return {}
}
}
function foo() {
let v: Validator & Partial<OnChanges> = null as any;
if (v instanceof C) {
v // Validator & Partial<OnChanges> & C
}
v // Validator & Partial<OnChanges> via subtype reduction
// In 4.1, we introduced a change which _fixed_ a bug with CFA
// correctly setting this to be the right object. With 4.2,
// we reverted that fix in #42231 which brought behavior back to
// before 4.1.
if (v.onChanges) {
~~~~~~~~~
!!! error TS2339: Property 'onChanges' does not exist on type 'C | (Validator & Partial<OnChanges>)'.
!!! error TS2339: Property 'onChanges' does not exist on type 'C'.
v.onChanges({});
~~~~~~~~~
!!! error TS2339: Property 'onChanges' does not exist on type 'C | (Validator & Partial<OnChanges>)'.
!!! error TS2339: Property 'onChanges' does not exist on type 'C'.
}
}