console.log(value)} />;
+class FieldFeedbackBeta extends React.Component
{
+ static defaultProps: BaseProps = {
+ when: () => true
+ };
+
+ render() {
+ return
Hello
;
+ }
+}
+
+// OK
+const Test1a = () => !!value} error>Hah;
+
+// Error: Void not assignable to boolean
+const Test2a = () => console.log(value)} error>Hah;
interface MyPropsProps extends Props {
when: (value: string) => boolean;
@@ -90,6 +106,23 @@ var FieldFeedback = /** @class */ (function (_super) {
var Test1 = function () { return react_1["default"].createElement(FieldFeedback, { when: function (value) { return !!value; } }); };
// Error: Void not assignable to boolean
var Test2 = function () { return react_1["default"].createElement(FieldFeedback, { when: function (value) { return console.log(value); } }); };
+var FieldFeedbackBeta = /** @class */ (function (_super) {
+ __extends(FieldFeedbackBeta, _super);
+ function FieldFeedbackBeta() {
+ return _super !== null && _super.apply(this, arguments) || this;
+ }
+ FieldFeedbackBeta.prototype.render = function () {
+ return react_1["default"].createElement("div", null, "Hello");
+ };
+ FieldFeedbackBeta.defaultProps = {
+ when: function () { return true; }
+ };
+ return FieldFeedbackBeta;
+}(react_1["default"].Component));
+// OK
+var Test1a = function () { return react_1["default"].createElement(FieldFeedbackBeta, { when: function (value) { return !!value; }, error: true }, "Hah"); };
+// Error: Void not assignable to boolean
+var Test2a = function () { return react_1["default"].createElement(FieldFeedbackBeta, { when: function (value) { return console.log(value); }, error: true }, "Hah"); };
var FieldFeedback2 = /** @class */ (function (_super) {
__extends(FieldFeedback2, _super);
function FieldFeedback2() {
diff --git a/tests/baselines/reference/reactDefaultPropsInferenceSuccess.symbols b/tests/baselines/reference/reactDefaultPropsInferenceSuccess.symbols
index dadaf9ea74520..f5cff116a4c2e 100644
--- a/tests/baselines/reference/reactDefaultPropsInferenceSuccess.symbols
+++ b/tests/baselines/reference/reactDefaultPropsInferenceSuccess.symbols
@@ -7,36 +7,39 @@ import React from 'react';
interface BaseProps {
>BaseProps : Symbol(BaseProps, Decl(reactDefaultPropsInferenceSuccess.tsx, 2, 26))
- when?: (value: string) => boolean;
+ when?: ((value: string) => boolean) | "a" | "b";
>when : Symbol(BaseProps.when, Decl(reactDefaultPropsInferenceSuccess.tsx, 4, 21))
->value : Symbol(value, Decl(reactDefaultPropsInferenceSuccess.tsx, 5, 10))
+>value : Symbol(value, Decl(reactDefaultPropsInferenceSuccess.tsx, 5, 11))
+
+ error?: boolean;
+>error : Symbol(BaseProps.error, Decl(reactDefaultPropsInferenceSuccess.tsx, 5, 50))
}
interface Props extends BaseProps {
->Props : Symbol(Props, Decl(reactDefaultPropsInferenceSuccess.tsx, 6, 1))
+>Props : Symbol(Props, Decl(reactDefaultPropsInferenceSuccess.tsx, 7, 1))
>BaseProps : Symbol(BaseProps, Decl(reactDefaultPropsInferenceSuccess.tsx, 2, 26))
}
class FieldFeedback extends React.Component
{
->FieldFeedback : Symbol(FieldFeedback, Decl(reactDefaultPropsInferenceSuccess.tsx, 9, 1))
->P : Symbol(P, Decl(reactDefaultPropsInferenceSuccess.tsx, 11, 20))
->Props : Symbol(Props, Decl(reactDefaultPropsInferenceSuccess.tsx, 6, 1))
+>FieldFeedback : Symbol(FieldFeedback, Decl(reactDefaultPropsInferenceSuccess.tsx, 10, 1))
+>P : Symbol(P, Decl(reactDefaultPropsInferenceSuccess.tsx, 12, 20))
+>Props : Symbol(Props, Decl(reactDefaultPropsInferenceSuccess.tsx, 7, 1))
>BaseProps : Symbol(BaseProps, Decl(reactDefaultPropsInferenceSuccess.tsx, 2, 26))
>React.Component : Symbol(React.Component, Decl(react16.d.ts, 345, 54), Decl(react16.d.ts, 349, 94))
>React : Symbol(React, Decl(reactDefaultPropsInferenceSuccess.tsx, 2, 6))
>Component : Symbol(React.Component, Decl(react16.d.ts, 345, 54), Decl(react16.d.ts, 349, 94))
->P : Symbol(P, Decl(reactDefaultPropsInferenceSuccess.tsx, 11, 20))
+>P : Symbol(P, Decl(reactDefaultPropsInferenceSuccess.tsx, 12, 20))
static defaultProps = {
->defaultProps : Symbol(FieldFeedback.defaultProps, Decl(reactDefaultPropsInferenceSuccess.tsx, 11, 77))
+>defaultProps : Symbol(FieldFeedback.defaultProps, Decl(reactDefaultPropsInferenceSuccess.tsx, 12, 77))
when: () => true
->when : Symbol(when, Decl(reactDefaultPropsInferenceSuccess.tsx, 12, 25))
+>when : Symbol(when, Decl(reactDefaultPropsInferenceSuccess.tsx, 13, 25))
};
render() {
->render : Symbol(FieldFeedback.render, Decl(reactDefaultPropsInferenceSuccess.tsx, 14, 4))
+>render : Symbol(FieldFeedback.render, Decl(reactDefaultPropsInferenceSuccess.tsx, 15, 4))
return
Hello
;
>div : Symbol(JSX.IntrinsicElements.div, Decl(react16.d.ts, 2420, 114))
@@ -46,58 +49,108 @@ class FieldFeedback extends React.Component
{
// OK
const Test1 = () => !!value} />;
->Test1 : Symbol(Test1, Decl(reactDefaultPropsInferenceSuccess.tsx, 22, 5))
->FieldFeedback : Symbol(FieldFeedback, Decl(reactDefaultPropsInferenceSuccess.tsx, 9, 1))
->when : Symbol(when, Decl(reactDefaultPropsInferenceSuccess.tsx, 22, 34))
->value : Symbol(value, Decl(reactDefaultPropsInferenceSuccess.tsx, 22, 41))
->value : Symbol(value, Decl(reactDefaultPropsInferenceSuccess.tsx, 22, 41))
+>Test1 : Symbol(Test1, Decl(reactDefaultPropsInferenceSuccess.tsx, 23, 5))
+>FieldFeedback : Symbol(FieldFeedback, Decl(reactDefaultPropsInferenceSuccess.tsx, 10, 1))
+>when : Symbol(when, Decl(reactDefaultPropsInferenceSuccess.tsx, 23, 34))
+>value : Symbol(value, Decl(reactDefaultPropsInferenceSuccess.tsx, 23, 41))
+>value : Symbol(value, Decl(reactDefaultPropsInferenceSuccess.tsx, 23, 41))
// Error: Void not assignable to boolean
const Test2 = () => console.log(value)} />;
->Test2 : Symbol(Test2, Decl(reactDefaultPropsInferenceSuccess.tsx, 25, 5))
->FieldFeedback : Symbol(FieldFeedback, Decl(reactDefaultPropsInferenceSuccess.tsx, 9, 1))
->when : Symbol(when, Decl(reactDefaultPropsInferenceSuccess.tsx, 25, 34))
->value : Symbol(value, Decl(reactDefaultPropsInferenceSuccess.tsx, 25, 41))
+>Test2 : Symbol(Test2, Decl(reactDefaultPropsInferenceSuccess.tsx, 26, 5))
+>FieldFeedback : Symbol(FieldFeedback, Decl(reactDefaultPropsInferenceSuccess.tsx, 10, 1))
+>when : Symbol(when, Decl(reactDefaultPropsInferenceSuccess.tsx, 26, 34))
+>value : Symbol(value, Decl(reactDefaultPropsInferenceSuccess.tsx, 26, 41))
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
->value : Symbol(value, Decl(reactDefaultPropsInferenceSuccess.tsx, 25, 41))
+>value : Symbol(value, Decl(reactDefaultPropsInferenceSuccess.tsx, 26, 41))
+
+class FieldFeedbackBeta extends React.Component
{
+>FieldFeedbackBeta : Symbol(FieldFeedbackBeta, Decl(reactDefaultPropsInferenceSuccess.tsx, 26, 73))
+>P : Symbol(P, Decl(reactDefaultPropsInferenceSuccess.tsx, 28, 24))
+>Props : Symbol(Props, Decl(reactDefaultPropsInferenceSuccess.tsx, 7, 1))
+>BaseProps : Symbol(BaseProps, Decl(reactDefaultPropsInferenceSuccess.tsx, 2, 26))
+>React.Component : Symbol(React.Component, Decl(react16.d.ts, 345, 54), Decl(react16.d.ts, 349, 94))
+>React : Symbol(React, Decl(reactDefaultPropsInferenceSuccess.tsx, 2, 6))
+>Component : Symbol(React.Component, Decl(react16.d.ts, 345, 54), Decl(react16.d.ts, 349, 94))
+>P : Symbol(P, Decl(reactDefaultPropsInferenceSuccess.tsx, 28, 24))
+
+ static defaultProps: BaseProps = {
+>defaultProps : Symbol(FieldFeedbackBeta.defaultProps, Decl(reactDefaultPropsInferenceSuccess.tsx, 28, 81))
+>BaseProps : Symbol(BaseProps, Decl(reactDefaultPropsInferenceSuccess.tsx, 2, 26))
+
+ when: () => true
+>when : Symbol(when, Decl(reactDefaultPropsInferenceSuccess.tsx, 29, 36))
+
+ };
+
+ render() {
+>render : Symbol(FieldFeedbackBeta.render, Decl(reactDefaultPropsInferenceSuccess.tsx, 31, 4))
+
+ return
Hello
;
+>div : Symbol(JSX.IntrinsicElements.div, Decl(react16.d.ts, 2420, 114))
+>div : Symbol(JSX.IntrinsicElements.div, Decl(react16.d.ts, 2420, 114))
+ }
+}
+// OK
+const Test1a = () => !!value} error>Hah;
+>Test1a : Symbol(Test1a, Decl(reactDefaultPropsInferenceSuccess.tsx, 39, 5))
+>FieldFeedbackBeta : Symbol(FieldFeedbackBeta, Decl(reactDefaultPropsInferenceSuccess.tsx, 26, 73))
+>when : Symbol(when, Decl(reactDefaultPropsInferenceSuccess.tsx, 39, 39))
+>value : Symbol(value, Decl(reactDefaultPropsInferenceSuccess.tsx, 39, 46))
+>value : Symbol(value, Decl(reactDefaultPropsInferenceSuccess.tsx, 39, 46))
+>error : Symbol(error, Decl(reactDefaultPropsInferenceSuccess.tsx, 39, 63))
+>FieldFeedbackBeta : Symbol(FieldFeedbackBeta, Decl(reactDefaultPropsInferenceSuccess.tsx, 26, 73))
+
+// Error: Void not assignable to boolean
+const Test2a = () => console.log(value)} error>Hah;
+>Test2a : Symbol(Test2a, Decl(reactDefaultPropsInferenceSuccess.tsx, 42, 5))
+>FieldFeedbackBeta : Symbol(FieldFeedbackBeta, Decl(reactDefaultPropsInferenceSuccess.tsx, 26, 73))
+>when : Symbol(when, Decl(reactDefaultPropsInferenceSuccess.tsx, 42, 39))
+>value : Symbol(value, Decl(reactDefaultPropsInferenceSuccess.tsx, 42, 46))
+>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
+>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
+>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
+>value : Symbol(value, Decl(reactDefaultPropsInferenceSuccess.tsx, 42, 46))
+>error : Symbol(error, Decl(reactDefaultPropsInferenceSuccess.tsx, 42, 74))
+>FieldFeedbackBeta : Symbol(FieldFeedbackBeta, Decl(reactDefaultPropsInferenceSuccess.tsx, 26, 73))
interface MyPropsProps extends Props {
->MyPropsProps : Symbol(MyPropsProps, Decl(reactDefaultPropsInferenceSuccess.tsx, 25, 73))
->Props : Symbol(Props, Decl(reactDefaultPropsInferenceSuccess.tsx, 6, 1))
+>MyPropsProps : Symbol(MyPropsProps, Decl(reactDefaultPropsInferenceSuccess.tsx, 42, 105))
+>Props : Symbol(Props, Decl(reactDefaultPropsInferenceSuccess.tsx, 7, 1))
when: (value: string) => boolean;
->when : Symbol(MyPropsProps.when, Decl(reactDefaultPropsInferenceSuccess.tsx, 28, 38))
->value : Symbol(value, Decl(reactDefaultPropsInferenceSuccess.tsx, 29, 9))
+>when : Symbol(MyPropsProps.when, Decl(reactDefaultPropsInferenceSuccess.tsx, 44, 38))
+>value : Symbol(value, Decl(reactDefaultPropsInferenceSuccess.tsx, 45, 9))
}
class FieldFeedback2 extends FieldFeedback
{
->FieldFeedback2 : Symbol(FieldFeedback2, Decl(reactDefaultPropsInferenceSuccess.tsx, 30, 1))
->P : Symbol(P, Decl(reactDefaultPropsInferenceSuccess.tsx, 32, 21))
->MyPropsProps : Symbol(MyPropsProps, Decl(reactDefaultPropsInferenceSuccess.tsx, 25, 73))
->MyPropsProps : Symbol(MyPropsProps, Decl(reactDefaultPropsInferenceSuccess.tsx, 25, 73))
->FieldFeedback : Symbol(FieldFeedback, Decl(reactDefaultPropsInferenceSuccess.tsx, 9, 1))
->P : Symbol(P, Decl(reactDefaultPropsInferenceSuccess.tsx, 32, 21))
+>FieldFeedback2 : Symbol(FieldFeedback2, Decl(reactDefaultPropsInferenceSuccess.tsx, 46, 1))
+>P : Symbol(P, Decl(reactDefaultPropsInferenceSuccess.tsx, 48, 21))
+>MyPropsProps : Symbol(MyPropsProps, Decl(reactDefaultPropsInferenceSuccess.tsx, 42, 105))
+>MyPropsProps : Symbol(MyPropsProps, Decl(reactDefaultPropsInferenceSuccess.tsx, 42, 105))
+>FieldFeedback : Symbol(FieldFeedback, Decl(reactDefaultPropsInferenceSuccess.tsx, 10, 1))
+>P : Symbol(P, Decl(reactDefaultPropsInferenceSuccess.tsx, 48, 21))
static defaultProps = {
->defaultProps : Symbol(FieldFeedback2.defaultProps, Decl(reactDefaultPropsInferenceSuccess.tsx, 32, 86))
+>defaultProps : Symbol(FieldFeedback2.defaultProps, Decl(reactDefaultPropsInferenceSuccess.tsx, 48, 86))
when: () => true
->when : Symbol(when, Decl(reactDefaultPropsInferenceSuccess.tsx, 33, 25))
+>when : Symbol(when, Decl(reactDefaultPropsInferenceSuccess.tsx, 49, 25))
};
render() {
->render : Symbol(FieldFeedback2.render, Decl(reactDefaultPropsInferenceSuccess.tsx, 35, 4))
+>render : Symbol(FieldFeedback2.render, Decl(reactDefaultPropsInferenceSuccess.tsx, 51, 4))
this.props.when("now"); // OK, always defined
->this.props.when : Symbol(when, Decl(reactDefaultPropsInferenceSuccess.tsx, 28, 38))
+>this.props.when : Symbol(when, Decl(reactDefaultPropsInferenceSuccess.tsx, 44, 38))
>this.props : Symbol(React.Component.props, Decl(react16.d.ts, 367, 32))
->this : Symbol(FieldFeedback2, Decl(reactDefaultPropsInferenceSuccess.tsx, 30, 1))
+>this : Symbol(FieldFeedback2, Decl(reactDefaultPropsInferenceSuccess.tsx, 46, 1))
>props : Symbol(React.Component.props, Decl(react16.d.ts, 367, 32))
->when : Symbol(when, Decl(reactDefaultPropsInferenceSuccess.tsx, 28, 38))
+>when : Symbol(when, Decl(reactDefaultPropsInferenceSuccess.tsx, 44, 38))
return
Hello
;
>div : Symbol(JSX.IntrinsicElements.div, Decl(react16.d.ts, 2420, 114))
@@ -107,25 +160,25 @@ class FieldFeedback2 extends FieldFeedbac
// OK
const Test3 = () => !!value} />;
->Test3 : Symbol(Test3, Decl(reactDefaultPropsInferenceSuccess.tsx, 44, 5))
->FieldFeedback2 : Symbol(FieldFeedback2, Decl(reactDefaultPropsInferenceSuccess.tsx, 30, 1))
->when : Symbol(when, Decl(reactDefaultPropsInferenceSuccess.tsx, 44, 35))
->value : Symbol(value, Decl(reactDefaultPropsInferenceSuccess.tsx, 44, 42))
->value : Symbol(value, Decl(reactDefaultPropsInferenceSuccess.tsx, 44, 42))
+>Test3 : Symbol(Test3, Decl(reactDefaultPropsInferenceSuccess.tsx, 60, 5))
+>FieldFeedback2 : Symbol(FieldFeedback2, Decl(reactDefaultPropsInferenceSuccess.tsx, 46, 1))
+>when : Symbol(when, Decl(reactDefaultPropsInferenceSuccess.tsx, 60, 35))
+>value : Symbol(value, Decl(reactDefaultPropsInferenceSuccess.tsx, 60, 42))
+>value : Symbol(value, Decl(reactDefaultPropsInferenceSuccess.tsx, 60, 42))
// Error: Void not assignable to boolean
const Test4 = () => console.log(value)} />;
->Test4 : Symbol(Test4, Decl(reactDefaultPropsInferenceSuccess.tsx, 47, 5))
->FieldFeedback2 : Symbol(FieldFeedback2, Decl(reactDefaultPropsInferenceSuccess.tsx, 30, 1))
->when : Symbol(when, Decl(reactDefaultPropsInferenceSuccess.tsx, 47, 35))
->value : Symbol(value, Decl(reactDefaultPropsInferenceSuccess.tsx, 47, 42))
+>Test4 : Symbol(Test4, Decl(reactDefaultPropsInferenceSuccess.tsx, 63, 5))
+>FieldFeedback2 : Symbol(FieldFeedback2, Decl(reactDefaultPropsInferenceSuccess.tsx, 46, 1))
+>when : Symbol(when, Decl(reactDefaultPropsInferenceSuccess.tsx, 63, 35))
+>value : Symbol(value, Decl(reactDefaultPropsInferenceSuccess.tsx, 63, 42))
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
->value : Symbol(value, Decl(reactDefaultPropsInferenceSuccess.tsx, 47, 42))
+>value : Symbol(value, Decl(reactDefaultPropsInferenceSuccess.tsx, 63, 42))
// OK
const Test5 = () => ;
->Test5 : Symbol(Test5, Decl(reactDefaultPropsInferenceSuccess.tsx, 50, 5))
->FieldFeedback2 : Symbol(FieldFeedback2, Decl(reactDefaultPropsInferenceSuccess.tsx, 30, 1))
+>Test5 : Symbol(Test5, Decl(reactDefaultPropsInferenceSuccess.tsx, 66, 5))
+>FieldFeedback2 : Symbol(FieldFeedback2, Decl(reactDefaultPropsInferenceSuccess.tsx, 46, 1))
diff --git a/tests/baselines/reference/reactDefaultPropsInferenceSuccess.types b/tests/baselines/reference/reactDefaultPropsInferenceSuccess.types
index 91d918b092347..bca297d3a1d18 100644
--- a/tests/baselines/reference/reactDefaultPropsInferenceSuccess.types
+++ b/tests/baselines/reference/reactDefaultPropsInferenceSuccess.types
@@ -5,9 +5,12 @@ import React from 'react';
>React : typeof React
interface BaseProps {
- when?: (value: string) => boolean;
->when : ((value: string) => boolean) | undefined
+ when?: ((value: string) => boolean) | "a" | "b";
+>when : "a" | "b" | ((value: string) => boolean) | undefined
>value : string
+
+ error?: boolean;
+>error : boolean | undefined
}
interface Props extends BaseProps {
@@ -68,6 +71,64 @@ const Test2 = () => console.log(value)} />;
>log : (message?: any, ...optionalParams: any[]) => void
>value : string
+class FieldFeedbackBeta extends React.Component
{
+>FieldFeedbackBeta : FieldFeedbackBeta
+>React.Component : React.Component
+>React : typeof React
+>Component : typeof React.Component
+
+ static defaultProps: BaseProps = {
+>defaultProps : BaseProps
+>{ when: () => true } : { when: () => true; }
+
+ when: () => true
+>when : () => true
+>() => true : () => true
+>true : true
+
+ };
+
+ render() {
+>render : () => JSX.Element
+
+ return
Hello
;
+>Hello
: JSX.Element
+>div : any
+>div : any
+ }
+}
+
+// OK
+const Test1a = () => !!value} error>Hah;
+>Test1a : () => JSX.Element
+>() => !!value} error>Hah : () => JSX.Element
+> !!value} error>Hah : JSX.Element
+>FieldFeedbackBeta : typeof FieldFeedbackBeta
+>when : (value: string) => boolean
+>value => !!value : (value: string) => boolean
+>value : string
+>!!value : boolean
+>!value : boolean
+>value : string
+>error : true
+>FieldFeedbackBeta : typeof FieldFeedbackBeta
+
+// Error: Void not assignable to boolean
+const Test2a = () => console.log(value)} error>Hah;
+>Test2a : () => JSX.Element
+>() => console.log(value)} error>Hah : () => JSX.Element
+> console.log(value)} error>Hah : JSX.Element
+>FieldFeedbackBeta : typeof FieldFeedbackBeta
+>when : (value: string) => void
+>value => console.log(value) : (value: string) => void
+>value : string
+>console.log(value) : void
+>console.log : (message?: any, ...optionalParams: any[]) => void
+>console : Console
+>log : (message?: any, ...optionalParams: any[]) => void
+>value : string
+>error : true
+>FieldFeedbackBeta : typeof FieldFeedbackBeta
interface MyPropsProps extends Props {
when: (value: string) => boolean;
diff --git a/tests/cases/compiler/reactDefaultPropsInferenceSuccess.tsx b/tests/cases/compiler/reactDefaultPropsInferenceSuccess.tsx
index 9de13d119df47..d1ee95995b9c2 100644
--- a/tests/cases/compiler/reactDefaultPropsInferenceSuccess.tsx
+++ b/tests/cases/compiler/reactDefaultPropsInferenceSuccess.tsx
@@ -6,7 +6,8 @@
import React from 'react';
interface BaseProps {
- when?: (value: string) => boolean;
+ when?: ((value: string) => boolean) | "a" | "b";
+ error?: boolean;
}
interface Props extends BaseProps {
@@ -28,6 +29,21 @@ const Test1 = () => !!value} />;
// Error: Void not assignable to boolean
const Test2 = () => console.log(value)} />;
+class FieldFeedbackBeta extends React.Component
{
+ static defaultProps: BaseProps = {
+ when: () => true
+ };
+
+ render() {
+ return
Hello
;
+ }
+}
+
+// OK
+const Test1a = () => !!value} error>Hah;
+
+// Error: Void not assignable to boolean
+const Test2a = () => console.log(value)} error>Hah;
interface MyPropsProps extends Props {
when: (value: string) => boolean;