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.
Instantiating a signature in the context of another should infer from…
… return type predicates if they match up (microsoft#30242) * Instantiating a signature in the context of another should infer from return type predicates if they match up * Invert condition per PR feedback
- Loading branch information
Showing
5 changed files
with
153 additions
and
0 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
49 changes: 49 additions & 0 deletions
49
tests/baselines/reference/returnTypePredicateIsInstantiateInContextOfTarget.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,49 @@ | ||
//// [returnTypePredicateIsInstantiateInContextOfTarget.tsx] | ||
/// <reference path="/.lib/react16.d.ts" /> | ||
import * as React from "react"; | ||
class TestComponent extends React.Component<{ isAny: <T>(obj: any) => obj is T }> { | ||
static defaultProps = { | ||
isAny: TestComponent.isAny | ||
} | ||
|
||
// Type guard is defined as a static class property | ||
static isAny<T>(obj: any): obj is T { | ||
return true; | ||
} | ||
} | ||
|
||
const TestRender = () => <TestComponent />; | ||
|
||
//// [returnTypePredicateIsInstantiateInContextOfTarget.js] | ||
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
}; | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
exports.__esModule = true; | ||
/// <reference path="react16.d.ts" /> | ||
var React = require("react"); | ||
var TestComponent = /** @class */ (function (_super) { | ||
__extends(TestComponent, _super); | ||
function TestComponent() { | ||
return _super !== null && _super.apply(this, arguments) || this; | ||
} | ||
// Type guard is defined as a static class property | ||
TestComponent.isAny = function (obj) { | ||
return true; | ||
}; | ||
TestComponent.defaultProps = { | ||
isAny: TestComponent.isAny | ||
}; | ||
return TestComponent; | ||
}(React.Component)); | ||
var TestRender = function () { return React.createElement(TestComponent, null); }; |
42 changes: 42 additions & 0 deletions
42
tests/baselines/reference/returnTypePredicateIsInstantiateInContextOfTarget.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,42 @@ | ||
=== tests/cases/compiler/returnTypePredicateIsInstantiateInContextOfTarget.tsx === | ||
/// <reference path="react16.d.ts" /> | ||
import * as React from "react"; | ||
>React : Symbol(React, Decl(returnTypePredicateIsInstantiateInContextOfTarget.tsx, 1, 6)) | ||
|
||
class TestComponent extends React.Component<{ isAny: <T>(obj: any) => obj is T }> { | ||
>TestComponent : Symbol(TestComponent, Decl(returnTypePredicateIsInstantiateInContextOfTarget.tsx, 1, 31)) | ||
>React.Component : Symbol(React.Component, Decl(react16.d.ts, 345, 54), Decl(react16.d.ts, 349, 94)) | ||
>React : Symbol(React, Decl(returnTypePredicateIsInstantiateInContextOfTarget.tsx, 1, 6)) | ||
>Component : Symbol(React.Component, Decl(react16.d.ts, 345, 54), Decl(react16.d.ts, 349, 94)) | ||
>isAny : Symbol(isAny, Decl(returnTypePredicateIsInstantiateInContextOfTarget.tsx, 2, 45)) | ||
>T : Symbol(T, Decl(returnTypePredicateIsInstantiateInContextOfTarget.tsx, 2, 54)) | ||
>obj : Symbol(obj, Decl(returnTypePredicateIsInstantiateInContextOfTarget.tsx, 2, 57)) | ||
>obj : Symbol(obj, Decl(returnTypePredicateIsInstantiateInContextOfTarget.tsx, 2, 57)) | ||
>T : Symbol(T, Decl(returnTypePredicateIsInstantiateInContextOfTarget.tsx, 2, 54)) | ||
|
||
static defaultProps = { | ||
>defaultProps : Symbol(TestComponent.defaultProps, Decl(returnTypePredicateIsInstantiateInContextOfTarget.tsx, 2, 83)) | ||
|
||
isAny: TestComponent.isAny | ||
>isAny : Symbol(isAny, Decl(returnTypePredicateIsInstantiateInContextOfTarget.tsx, 3, 27)) | ||
>TestComponent.isAny : Symbol(TestComponent.isAny, Decl(returnTypePredicateIsInstantiateInContextOfTarget.tsx, 5, 5)) | ||
>TestComponent : Symbol(TestComponent, Decl(returnTypePredicateIsInstantiateInContextOfTarget.tsx, 1, 31)) | ||
>isAny : Symbol(TestComponent.isAny, Decl(returnTypePredicateIsInstantiateInContextOfTarget.tsx, 5, 5)) | ||
} | ||
|
||
// Type guard is defined as a static class property | ||
static isAny<T>(obj: any): obj is T { | ||
>isAny : Symbol(TestComponent.isAny, Decl(returnTypePredicateIsInstantiateInContextOfTarget.tsx, 5, 5)) | ||
>T : Symbol(T, Decl(returnTypePredicateIsInstantiateInContextOfTarget.tsx, 8, 17)) | ||
>obj : Symbol(obj, Decl(returnTypePredicateIsInstantiateInContextOfTarget.tsx, 8, 20)) | ||
>obj : Symbol(obj, Decl(returnTypePredicateIsInstantiateInContextOfTarget.tsx, 8, 20)) | ||
>T : Symbol(T, Decl(returnTypePredicateIsInstantiateInContextOfTarget.tsx, 8, 17)) | ||
|
||
return true; | ||
} | ||
} | ||
|
||
const TestRender = () => <TestComponent />; | ||
>TestRender : Symbol(TestRender, Decl(returnTypePredicateIsInstantiateInContextOfTarget.tsx, 13, 5)) | ||
>TestComponent : Symbol(TestComponent, Decl(returnTypePredicateIsInstantiateInContextOfTarget.tsx, 1, 31)) | ||
|
40 changes: 40 additions & 0 deletions
40
tests/baselines/reference/returnTypePredicateIsInstantiateInContextOfTarget.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,40 @@ | ||
=== tests/cases/compiler/returnTypePredicateIsInstantiateInContextOfTarget.tsx === | ||
/// <reference path="react16.d.ts" /> | ||
import * as React from "react"; | ||
>React : typeof React | ||
|
||
class TestComponent extends React.Component<{ isAny: <T>(obj: any) => obj is T }> { | ||
>TestComponent : TestComponent | ||
>React.Component : React.Component<{ isAny: <T>(obj: any) => obj is T; }, {}, any> | ||
>React : typeof React | ||
>Component : typeof React.Component | ||
>isAny : <T>(obj: any) => obj is T | ||
>obj : any | ||
|
||
static defaultProps = { | ||
>defaultProps : { isAny: <T>(obj: any) => obj is T; } | ||
>{ isAny: TestComponent.isAny } : { isAny: <T>(obj: any) => obj is T; } | ||
|
||
isAny: TestComponent.isAny | ||
>isAny : <T>(obj: any) => obj is T | ||
>TestComponent.isAny : <T>(obj: any) => obj is T | ||
>TestComponent : typeof TestComponent | ||
>isAny : <T>(obj: any) => obj is T | ||
} | ||
|
||
// Type guard is defined as a static class property | ||
static isAny<T>(obj: any): obj is T { | ||
>isAny : <T>(obj: any) => obj is T | ||
>obj : any | ||
|
||
return true; | ||
>true : true | ||
} | ||
} | ||
|
||
const TestRender = () => <TestComponent />; | ||
>TestRender : () => JSX.Element | ||
>() => <TestComponent /> : () => JSX.Element | ||
><TestComponent /> : JSX.Element | ||
>TestComponent : typeof TestComponent | ||
|
16 changes: 16 additions & 0 deletions
16
tests/cases/compiler/returnTypePredicateIsInstantiateInContextOfTarget.tsx
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,16 @@ | ||
// @jsx: react | ||
// @strict: true | ||
/// <reference path="/.lib/react16.d.ts" /> | ||
import * as React from "react"; | ||
class TestComponent extends React.Component<{ isAny: <T>(obj: any) => obj is T }> { | ||
static defaultProps = { | ||
isAny: TestComponent.isAny | ||
} | ||
|
||
// Type guard is defined as a static class property | ||
static isAny<T>(obj: any): obj is T { | ||
return true; | ||
} | ||
} | ||
|
||
const TestRender = () => <TestComponent />; |