-
Notifications
You must be signed in to change notification settings - Fork 12.8k
[Master] Fix 11566 - Allow SFC to return null #14102
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
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,24 @@ | ||
//// [file.tsx] | ||
|
||
import React = require('react'); | ||
|
||
const Foo = (props: any) => null; | ||
|
||
function Greet(x: {name?: string}) { | ||
return null; | ||
} | ||
|
||
const foo = <Foo />; | ||
const G = <Greet />; | ||
|
||
//// [file.jsx] | ||
define(["require", "exports", "react"], function (require, exports, React) { | ||
"use strict"; | ||
exports.__esModule = true; | ||
var Foo = function (props) { return null; }; | ||
function Greet(x) { | ||
return null; | ||
} | ||
var foo = <Foo />; | ||
var G = <Greet />; | ||
}); |
This file contains hidden or 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,25 @@ | ||
=== tests/cases/conformance/jsx/file.tsx === | ||
|
||
import React = require('react'); | ||
>React : Symbol(React, Decl(file.tsx, 0, 0)) | ||
|
||
const Foo = (props: any) => null; | ||
>Foo : Symbol(Foo, Decl(file.tsx, 3, 5)) | ||
>props : Symbol(props, Decl(file.tsx, 3, 13)) | ||
|
||
function Greet(x: {name?: string}) { | ||
>Greet : Symbol(Greet, Decl(file.tsx, 3, 33)) | ||
>x : Symbol(x, Decl(file.tsx, 5, 15)) | ||
>name : Symbol(name, Decl(file.tsx, 5, 19)) | ||
|
||
return null; | ||
} | ||
|
||
const foo = <Foo />; | ||
>foo : Symbol(foo, Decl(file.tsx, 9, 5)) | ||
>Foo : Symbol(Foo, Decl(file.tsx, 3, 5)) | ||
|
||
const G = <Greet />; | ||
>G : Symbol(G, Decl(file.tsx, 10, 5)) | ||
>Greet : Symbol(Greet, Decl(file.tsx, 3, 33)) | ||
|
This file contains hidden or 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,30 @@ | ||
=== tests/cases/conformance/jsx/file.tsx === | ||
|
||
import React = require('react'); | ||
>React : typeof React | ||
|
||
const Foo = (props: any) => null; | ||
>Foo : (props: any) => any | ||
>(props: any) => null : (props: any) => any | ||
>props : any | ||
>null : null | ||
|
||
function Greet(x: {name?: string}) { | ||
>Greet : (x: { name?: string; }) => any | ||
>x : { name?: string; } | ||
>name : string | ||
|
||
return null; | ||
>null : null | ||
} | ||
|
||
const foo = <Foo />; | ||
>foo : JSX.Element | ||
><Foo /> : JSX.Element | ||
>Foo : (props: any) => any | ||
|
||
const G = <Greet />; | ||
>G : JSX.Element | ||
><Greet /> : JSX.Element | ||
>Greet : (x: { name?: string; }) => any | ||
|
24 changes: 24 additions & 0 deletions
24
tests/baselines/reference/tsxSFCReturnNullStrictNullChecks.js
This file contains hidden or 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,24 @@ | ||
//// [file.tsx] | ||
|
||
import React = require('react'); | ||
|
||
const Foo = (props: any) => null; | ||
|
||
function Greet(x: {name?: string}) { | ||
return null; | ||
} | ||
|
||
const foo = <Foo />; | ||
const G = <Greet />; | ||
|
||
//// [file.jsx] | ||
define(["require", "exports", "react"], function (require, exports, React) { | ||
"use strict"; | ||
exports.__esModule = true; | ||
var Foo = function (props) { return null; }; | ||
function Greet(x) { | ||
return null; | ||
} | ||
var foo = <Foo />; | ||
var G = <Greet />; | ||
}); |
25 changes: 25 additions & 0 deletions
25
tests/baselines/reference/tsxSFCReturnNullStrictNullChecks.symbols
This file contains hidden or 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,25 @@ | ||
=== tests/cases/conformance/jsx/file.tsx === | ||
|
||
import React = require('react'); | ||
>React : Symbol(React, Decl(file.tsx, 0, 0)) | ||
|
||
const Foo = (props: any) => null; | ||
>Foo : Symbol(Foo, Decl(file.tsx, 3, 5)) | ||
>props : Symbol(props, Decl(file.tsx, 3, 13)) | ||
|
||
function Greet(x: {name?: string}) { | ||
>Greet : Symbol(Greet, Decl(file.tsx, 3, 33)) | ||
>x : Symbol(x, Decl(file.tsx, 5, 15)) | ||
>name : Symbol(name, Decl(file.tsx, 5, 19)) | ||
|
||
return null; | ||
} | ||
|
||
const foo = <Foo />; | ||
>foo : Symbol(foo, Decl(file.tsx, 9, 5)) | ||
>Foo : Symbol(Foo, Decl(file.tsx, 3, 5)) | ||
|
||
const G = <Greet />; | ||
>G : Symbol(G, Decl(file.tsx, 10, 5)) | ||
>Greet : Symbol(Greet, Decl(file.tsx, 3, 33)) | ||
|
30 changes: 30 additions & 0 deletions
30
tests/baselines/reference/tsxSFCReturnNullStrictNullChecks.types
This file contains hidden or 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,30 @@ | ||
=== tests/cases/conformance/jsx/file.tsx === | ||
|
||
import React = require('react'); | ||
>React : typeof React | ||
|
||
const Foo = (props: any) => null; | ||
>Foo : (props: any) => null | ||
>(props: any) => null : (props: any) => null | ||
>props : any | ||
>null : null | ||
|
||
function Greet(x: {name?: string}) { | ||
>Greet : (x: { name?: string | undefined; }) => null | ||
>x : { name?: string | undefined; } | ||
>name : string | undefined | ||
|
||
return null; | ||
>null : null | ||
} | ||
|
||
const foo = <Foo />; | ||
>foo : JSX.Element | ||
><Foo /> : JSX.Element | ||
>Foo : (props: any) => null | ||
|
||
const G = <Greet />; | ||
>G : JSX.Element | ||
><Greet /> : JSX.Element | ||
>Greet : (x: { name?: string | undefined; }) => null | ||
|
20 changes: 20 additions & 0 deletions
20
tests/baselines/reference/tsxSFCReturnUndefinedStrictNullChecks.errors.txt
This file contains hidden or 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,20 @@ | ||
tests/cases/conformance/jsx/file.tsx(10,13): error TS2605: JSX element type 'undefined' is not a constructor function for JSX elements. | ||
tests/cases/conformance/jsx/file.tsx(11,11): error TS2605: JSX element type 'undefined' is not a constructor function for JSX elements. | ||
|
||
|
||
==== tests/cases/conformance/jsx/file.tsx (2 errors) ==== | ||
|
||
import React = require('react'); | ||
|
||
const Foo = (props: any) => undefined; | ||
function Greet(x: {name?: string}) { | ||
return undefined; | ||
} | ||
|
||
// Error | ||
const foo = <Foo />; | ||
~~~~~~~ | ||
!!! error TS2605: JSX element type 'undefined' is not a constructor function for JSX elements. | ||
const G = <Greet />; | ||
~~~~~~~~~ | ||
!!! error TS2605: JSX element type 'undefined' is not a constructor function for JSX elements. |
25 changes: 25 additions & 0 deletions
25
tests/baselines/reference/tsxSFCReturnUndefinedStrictNullChecks.js
This file contains hidden or 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,25 @@ | ||
//// [file.tsx] | ||
|
||
import React = require('react'); | ||
|
||
const Foo = (props: any) => undefined; | ||
function Greet(x: {name?: string}) { | ||
return undefined; | ||
} | ||
|
||
// Error | ||
const foo = <Foo />; | ||
const G = <Greet />; | ||
|
||
//// [file.jsx] | ||
define(["require", "exports", "react"], function (require, exports, React) { | ||
"use strict"; | ||
exports.__esModule = true; | ||
var Foo = function (props) { return undefined; }; | ||
function Greet(x) { | ||
return undefined; | ||
} | ||
// Error | ||
var foo = <Foo />; | ||
var G = <Greet />; | ||
}); |
This file contains hidden or 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 @@ | ||
// @filename: file.tsx | ||
// @jsx: preserve | ||
// @module: amd | ||
// @noLib: true | ||
// @libFiles: react.d.ts,lib.d.ts | ||
|
||
import React = require('react'); | ||
|
||
const Foo = (props: any) => null; | ||
|
||
function Greet(x: {name?: string}) { | ||
return null; | ||
} | ||
|
||
const foo = <Foo />; | ||
const G = <Greet />; |
17 changes: 17 additions & 0 deletions
17
tests/cases/conformance/jsx/tsxSFCReturnNullStrictNullChecks.tsx
This file contains hidden or 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,17 @@ | ||
// @filename: file.tsx | ||
// @jsx: preserve | ||
// @module: amd | ||
// @noLib: true | ||
// @strictNullChecks: true | ||
// @libFiles: react.d.ts,lib.d.ts | ||
|
||
import React = require('react'); | ||
|
||
const Foo = (props: any) => null; | ||
|
||
function Greet(x: {name?: string}) { | ||
return null; | ||
} | ||
|
||
const foo = <Foo />; | ||
const G = <Greet />; |
17 changes: 17 additions & 0 deletions
17
tests/cases/conformance/jsx/tsxSFCReturnUndefinedStrictNullChecks.tsx
This file contains hidden or 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,17 @@ | ||
// @filename: file.tsx | ||
// @jsx: preserve | ||
// @module: amd | ||
// @noLib: true | ||
// @strictNullChecks: true | ||
// @libFiles: react.d.ts,lib.d.ts | ||
|
||
import React = require('react'); | ||
|
||
const Foo = (props: any) => undefined; | ||
function Greet(x: {name?: string}) { | ||
return undefined; | ||
} | ||
|
||
// Error | ||
const foo = <Foo />; | ||
const G = <Greet />; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I change this to use memoize so it is similar to how we handle other type (see below)....now to think about it, it may have additional cause of function call...