forked from microsoft/TypeScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reinterpret a type parameter constrained to any as an upper bound con…
…straint (microsoft#29571) * Reinterpret a type parameter constrained to any as an upper bound constraint * Use real constraqint in alias in test Co-authored-by: Nathan Shively-Sanders <[email protected]>
- Loading branch information
Showing
21 changed files
with
254 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
tests/baselines/reference/jsxExcessPropsAndAssignability.errors.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
tests/cases/compiler/jsxExcessPropsAndAssignability.tsx(16,6): error TS2322: Type 'ComposedComponentProps & { myProp: number; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<Component<WrapperComponentProps, any, any>> & Readonly<{ children?: ReactNode; }> & Readonly<WrapperComponentProps>'. | ||
Type 'ComposedComponentProps & { myProp: number; }' is not assignable to type 'Readonly<WrapperComponentProps>'. | ||
|
||
|
||
==== tests/cases/compiler/jsxExcessPropsAndAssignability.tsx (1 errors) ==== | ||
/// <reference path="/.lib/react16.d.ts" /> | ||
|
||
import * as React from 'react'; | ||
|
||
const myHoc = <ComposedComponentProps extends any>( | ||
ComposedComponent: React.ComponentClass<ComposedComponentProps>, | ||
) => { | ||
type WrapperComponentProps = ComposedComponentProps & { myProp: string }; | ||
const WrapperComponent: React.ComponentClass<WrapperComponentProps> = null as any; | ||
|
||
const props: ComposedComponentProps = null as any; | ||
|
||
// Expected no error, got none - good | ||
<WrapperComponent {...props} myProp={'1000000'} />; | ||
// Expected error, but got none - bad! | ||
<WrapperComponent {...props} myProp={1000000} />; | ||
~~~~~~~~~~~~~~~~ | ||
!!! error TS2322: Type 'ComposedComponentProps & { myProp: number; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<Component<WrapperComponentProps, any, any>> & Readonly<{ children?: ReactNode; }> & Readonly<WrapperComponentProps>'. | ||
!!! error TS2322: Type 'ComposedComponentProps & { myProp: number; }' is not assignable to type 'Readonly<WrapperComponentProps>'. | ||
}; | ||
|
44 changes: 44 additions & 0 deletions
44
tests/baselines/reference/jsxExcessPropsAndAssignability.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
//// [jsxExcessPropsAndAssignability.tsx] | ||
/// <reference path="/.lib/react16.d.ts" /> | ||
|
||
import * as React from 'react'; | ||
|
||
const myHoc = <ComposedComponentProps extends any>( | ||
ComposedComponent: React.ComponentClass<ComposedComponentProps>, | ||
) => { | ||
type WrapperComponentProps = ComposedComponentProps & { myProp: string }; | ||
const WrapperComponent: React.ComponentClass<WrapperComponentProps> = null as any; | ||
|
||
const props: ComposedComponentProps = null as any; | ||
|
||
// Expected no error, got none - good | ||
<WrapperComponent {...props} myProp={'1000000'} />; | ||
// Expected error, but got none - bad! | ||
<WrapperComponent {...props} myProp={1000000} />; | ||
}; | ||
|
||
|
||
//// [jsxExcessPropsAndAssignability.js] | ||
"use strict"; | ||
/// <reference path="react16.d.ts" /> | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
exports.__esModule = true; | ||
var React = require("react"); | ||
var myHoc = function (ComposedComponent) { | ||
var WrapperComponent = null; | ||
var props = null; | ||
// Expected no error, got none - good | ||
React.createElement(WrapperComponent, __assign({}, props, { myProp: '1000000' })); | ||
// Expected error, but got none - bad! | ||
React.createElement(WrapperComponent, __assign({}, props, { myProp: 1000000 })); | ||
}; |
46 changes: 46 additions & 0 deletions
46
tests/baselines/reference/jsxExcessPropsAndAssignability.symbols
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
=== tests/cases/compiler/jsxExcessPropsAndAssignability.tsx === | ||
/// <reference path="react16.d.ts" /> | ||
|
||
import * as React from 'react'; | ||
>React : Symbol(React, Decl(jsxExcessPropsAndAssignability.tsx, 2, 6)) | ||
|
||
const myHoc = <ComposedComponentProps extends any>( | ||
>myHoc : Symbol(myHoc, Decl(jsxExcessPropsAndAssignability.tsx, 4, 5)) | ||
>ComposedComponentProps : Symbol(ComposedComponentProps, Decl(jsxExcessPropsAndAssignability.tsx, 4, 15)) | ||
|
||
ComposedComponent: React.ComponentClass<ComposedComponentProps>, | ||
>ComposedComponent : Symbol(ComposedComponent, Decl(jsxExcessPropsAndAssignability.tsx, 4, 51)) | ||
>React : Symbol(React, Decl(jsxExcessPropsAndAssignability.tsx, 2, 6)) | ||
>ComponentClass : Symbol(React.ComponentClass, Decl(react16.d.ts, 421, 9)) | ||
>ComposedComponentProps : Symbol(ComposedComponentProps, Decl(jsxExcessPropsAndAssignability.tsx, 4, 15)) | ||
|
||
) => { | ||
type WrapperComponentProps = ComposedComponentProps & { myProp: string }; | ||
>WrapperComponentProps : Symbol(WrapperComponentProps, Decl(jsxExcessPropsAndAssignability.tsx, 6, 6)) | ||
>ComposedComponentProps : Symbol(ComposedComponentProps, Decl(jsxExcessPropsAndAssignability.tsx, 4, 15)) | ||
>myProp : Symbol(myProp, Decl(jsxExcessPropsAndAssignability.tsx, 7, 59)) | ||
|
||
const WrapperComponent: React.ComponentClass<WrapperComponentProps> = null as any; | ||
>WrapperComponent : Symbol(WrapperComponent, Decl(jsxExcessPropsAndAssignability.tsx, 8, 9)) | ||
>React : Symbol(React, Decl(jsxExcessPropsAndAssignability.tsx, 2, 6)) | ||
>ComponentClass : Symbol(React.ComponentClass, Decl(react16.d.ts, 421, 9)) | ||
>WrapperComponentProps : Symbol(WrapperComponentProps, Decl(jsxExcessPropsAndAssignability.tsx, 6, 6)) | ||
|
||
const props: ComposedComponentProps = null as any; | ||
>props : Symbol(props, Decl(jsxExcessPropsAndAssignability.tsx, 10, 9)) | ||
>ComposedComponentProps : Symbol(ComposedComponentProps, Decl(jsxExcessPropsAndAssignability.tsx, 4, 15)) | ||
|
||
// Expected no error, got none - good | ||
<WrapperComponent {...props} myProp={'1000000'} />; | ||
>WrapperComponent : Symbol(WrapperComponent, Decl(jsxExcessPropsAndAssignability.tsx, 8, 9)) | ||
>props : Symbol(props, Decl(jsxExcessPropsAndAssignability.tsx, 10, 9)) | ||
>myProp : Symbol(myProp, Decl(jsxExcessPropsAndAssignability.tsx, 13, 32)) | ||
|
||
// Expected error, but got none - bad! | ||
<WrapperComponent {...props} myProp={1000000} />; | ||
>WrapperComponent : Symbol(WrapperComponent, Decl(jsxExcessPropsAndAssignability.tsx, 8, 9)) | ||
>props : Symbol(props, Decl(jsxExcessPropsAndAssignability.tsx, 10, 9)) | ||
>myProp : Symbol(myProp, Decl(jsxExcessPropsAndAssignability.tsx, 15, 32)) | ||
|
||
}; | ||
|
48 changes: 48 additions & 0 deletions
48
tests/baselines/reference/jsxExcessPropsAndAssignability.types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
=== tests/cases/compiler/jsxExcessPropsAndAssignability.tsx === | ||
/// <reference path="react16.d.ts" /> | ||
|
||
import * as React from 'react'; | ||
>React : typeof React | ||
|
||
const myHoc = <ComposedComponentProps extends any>( | ||
>myHoc : <ComposedComponentProps extends unknown>(ComposedComponent: React.ComponentClass<ComposedComponentProps, any>) => void | ||
><ComposedComponentProps extends any>( ComposedComponent: React.ComponentClass<ComposedComponentProps>,) => { type WrapperComponentProps = ComposedComponentProps & { myProp: string }; const WrapperComponent: React.ComponentClass<WrapperComponentProps> = null as any; const props: ComposedComponentProps = null as any; // Expected no error, got none - good <WrapperComponent {...props} myProp={'1000000'} />; // Expected error, but got none - bad! <WrapperComponent {...props} myProp={1000000} />;} : <ComposedComponentProps extends unknown>(ComposedComponent: React.ComponentClass<ComposedComponentProps, any>) => void | ||
|
||
ComposedComponent: React.ComponentClass<ComposedComponentProps>, | ||
>ComposedComponent : React.ComponentClass<ComposedComponentProps, any> | ||
>React : any | ||
|
||
) => { | ||
type WrapperComponentProps = ComposedComponentProps & { myProp: string }; | ||
>WrapperComponentProps : ComposedComponentProps & { myProp: string; } | ||
>myProp : string | ||
|
||
const WrapperComponent: React.ComponentClass<WrapperComponentProps> = null as any; | ||
>WrapperComponent : React.ComponentClass<ComposedComponentProps & { myProp: string; }, any> | ||
>React : any | ||
>null as any : any | ||
>null : null | ||
|
||
const props: ComposedComponentProps = null as any; | ||
>props : ComposedComponentProps | ||
>null as any : any | ||
>null : null | ||
|
||
// Expected no error, got none - good | ||
<WrapperComponent {...props} myProp={'1000000'} />; | ||
><WrapperComponent {...props} myProp={'1000000'} /> : JSX.Element | ||
>WrapperComponent : React.ComponentClass<ComposedComponentProps & { myProp: string; }, any> | ||
>props : ComposedComponentProps | ||
>myProp : "1000000" | ||
>'1000000' : "1000000" | ||
|
||
// Expected error, but got none - bad! | ||
<WrapperComponent {...props} myProp={1000000} />; | ||
><WrapperComponent {...props} myProp={1000000} /> : JSX.Element | ||
>WrapperComponent : React.ComponentClass<ComposedComponentProps & { myProp: string; }, any> | ||
>props : ComposedComponentProps | ||
>myProp : number | ||
>1000000 : 1000000 | ||
|
||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.