Skip to content

Common properties check:Fix intersection-parent check #34646

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
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
98 changes: 55 additions & 43 deletions src/compiler/checker.ts

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions tests/baselines/reference/commonTypeIntersection.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
tests/cases/conformance/types/intersection/commonTypeIntersection.ts(2,5): error TS2326: Types of property '__typename' are incompatible.
Type '"TypeTwo" | undefined' is not assignable to type '"TypeOne" | undefined'.
Type '"TypeTwo"' is not assignable to type '"TypeOne" | undefined'.
tests/cases/conformance/types/intersection/commonTypeIntersection.ts(4,5): error TS2326: Types of property '__typename' are incompatible.
Type '"TypeTwo" | undefined' is not assignable to type '"TypeOne" | undefined'.
Type '"TypeTwo"' is not assignable to type '"TypeOne" | undefined'.


==== tests/cases/conformance/types/intersection/commonTypeIntersection.ts (2 errors) ====
declare let x1: { __typename?: 'TypeTwo' } & { a: boolean };
let y1: { __typename?: 'TypeOne' } & { a: boolean} = x1; // No error!
~~
!!! error TS2326: Types of property '__typename' are incompatible.
!!! error TS2326: Type '"TypeTwo" | undefined' is not assignable to type '"TypeOne" | undefined'.
!!! error TS2326: Type '"TypeTwo"' is not assignable to type '"TypeOne" | undefined'.
declare let x2: { __typename?: 'TypeTwo' } & string;
let y2: { __typename?: 'TypeOne' } & string = x2; // No error!
~~
!!! error TS2326: Types of property '__typename' are incompatible.
!!! error TS2326: Type '"TypeTwo" | undefined' is not assignable to type '"TypeOne" | undefined'.
!!! error TS2326: Type '"TypeTwo"' is not assignable to type '"TypeOne" | undefined'.

11 changes: 11 additions & 0 deletions tests/baselines/reference/commonTypeIntersection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//// [commonTypeIntersection.ts]
declare let x1: { __typename?: 'TypeTwo' } & { a: boolean };
let y1: { __typename?: 'TypeOne' } & { a: boolean} = x1; // No error!
declare let x2: { __typename?: 'TypeTwo' } & string;
let y2: { __typename?: 'TypeOne' } & string = x2; // No error!


//// [commonTypeIntersection.js]
"use strict";
var y1 = x1; // No error!
var y2 = x2; // No error!
21 changes: 21 additions & 0 deletions tests/baselines/reference/commonTypeIntersection.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
=== tests/cases/conformance/types/intersection/commonTypeIntersection.ts ===
declare let x1: { __typename?: 'TypeTwo' } & { a: boolean };
>x1 : Symbol(x1, Decl(commonTypeIntersection.ts, 0, 11))
>__typename : Symbol(__typename, Decl(commonTypeIntersection.ts, 0, 17))
>a : Symbol(a, Decl(commonTypeIntersection.ts, 0, 46))

let y1: { __typename?: 'TypeOne' } & { a: boolean} = x1; // No error!
>y1 : Symbol(y1, Decl(commonTypeIntersection.ts, 1, 3))
>__typename : Symbol(__typename, Decl(commonTypeIntersection.ts, 1, 9))
>a : Symbol(a, Decl(commonTypeIntersection.ts, 1, 38))
>x1 : Symbol(x1, Decl(commonTypeIntersection.ts, 0, 11))

declare let x2: { __typename?: 'TypeTwo' } & string;
>x2 : Symbol(x2, Decl(commonTypeIntersection.ts, 2, 11))
>__typename : Symbol(__typename, Decl(commonTypeIntersection.ts, 2, 17))

let y2: { __typename?: 'TypeOne' } & string = x2; // No error!
>y2 : Symbol(y2, Decl(commonTypeIntersection.ts, 3, 3))
>__typename : Symbol(__typename, Decl(commonTypeIntersection.ts, 3, 9))
>x2 : Symbol(x2, Decl(commonTypeIntersection.ts, 2, 11))

21 changes: 21 additions & 0 deletions tests/baselines/reference/commonTypeIntersection.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
=== tests/cases/conformance/types/intersection/commonTypeIntersection.ts ===
declare let x1: { __typename?: 'TypeTwo' } & { a: boolean };
>x1 : { __typename?: "TypeTwo" | undefined; } & { a: boolean; }
>__typename : "TypeTwo" | undefined
>a : boolean

let y1: { __typename?: 'TypeOne' } & { a: boolean} = x1; // No error!
>y1 : { __typename?: "TypeOne" | undefined; } & { a: boolean; }
>__typename : "TypeOne" | undefined
>a : boolean
>x1 : { __typename?: "TypeTwo" | undefined; } & { a: boolean; }

declare let x2: { __typename?: 'TypeTwo' } & string;
>x2 : { __typename?: "TypeTwo" | undefined; } & string
>__typename : "TypeTwo" | undefined

let y2: { __typename?: 'TypeOne' } & string = x2; // No error!
>y2 : { __typename?: "TypeOne" | undefined; } & string
>__typename : "TypeOne" | undefined
>x2 : { __typename?: "TypeTwo" | undefined; } & string

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
tests/cases/compiler/reactReadonlyHOCAssignabilityReal.tsx(7,21): error TS2326: Types of property 'name' are incompatible.
Type '"Matt"' is not assignable to type 'P["name"] & string'.
Type '"Matt"' is not assignable to type 'P["name"]'.


==== tests/cases/compiler/reactReadonlyHOCAssignabilityReal.tsx (1 errors) ====
/// <reference path="/.lib/react16.d.ts" />
import * as React from "react";

function myHigherOrderComponent<P>(Inner: React.ComponentClass<P & {name: string}>): React.ComponentClass<P> {
return class OuterComponent extends React.Component<P> {
render() {
return <Inner {...this.props} name="Matt"/>;
~~~~~
!!! error TS2326: Types of property 'name' are incompatible.
!!! error TS2326: Type '"Matt"' is not assignable to type 'P["name"] & string'.
!!! error TS2326: Type '"Matt"' is not assignable to type 'P["name"]'.
}
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function myHigherOrderComponent<P>(Inner: React.ComponentClass<P & {name: string
>this.props : Readonly<{ children?: React.ReactNode; }> & Readonly<P>
>this : this
>props : Readonly<{ children?: React.ReactNode; }> & Readonly<P>
>name : "Matt"
>name : string
}
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// @strict: true
declare let x1: { __typename?: 'TypeTwo' } & { a: boolean };
let y1: { __typename?: 'TypeOne' } & { a: boolean} = x1; // No error!
declare let x2: { __typename?: 'TypeTwo' } & string;
let y2: { __typename?: 'TypeOne' } & string = x2; // No error!