-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Fake up value declaration for synthetic jsx children symbol so they get excess property checked #29359
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
Merged
weswigham
merged 1 commit into
microsoft:master
from
weswigham:excess-props-jsx-children
Jan 16, 2019
Merged
Fake up value declaration for synthetic jsx children symbol so they get excess property checked #29359
Changes from all commits
Commits
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
31 changes: 31 additions & 0 deletions
31
tests/baselines/reference/checkJsxChildrenProperty15.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,31 @@ | ||
tests/cases/conformance/jsx/file.tsx(10,13): error TS2322: Type '{ children: Element; }' is not assignable to type 'IntrinsicAttributes'. | ||
Property 'children' does not exist on type 'IntrinsicAttributes'. | ||
tests/cases/conformance/jsx/file.tsx(11,13): error TS2322: Type '{ children: Element; key: string; }' is not assignable to type 'IntrinsicAttributes'. | ||
Property 'children' does not exist on type 'IntrinsicAttributes'. | ||
tests/cases/conformance/jsx/file.tsx(12,13): error TS2322: Type '{ children: Element[]; key: string; }' is not assignable to type 'IntrinsicAttributes'. | ||
Property 'children' does not exist on type 'IntrinsicAttributes'. | ||
|
||
|
||
==== tests/cases/conformance/jsx/file.tsx (3 errors) ==== | ||
import React = require('react'); | ||
|
||
const Tag = (x: {}) => <div></div>; | ||
|
||
// OK | ||
const k1 = <Tag />; | ||
const k2 = <Tag></Tag>; | ||
|
||
// Not OK (excess children) | ||
const k3 = <Tag children={<div></div>} />; | ||
~~~ | ||
!!! error TS2322: Type '{ children: Element; }' is not assignable to type 'IntrinsicAttributes'. | ||
!!! error TS2322: Property 'children' does not exist on type 'IntrinsicAttributes'. | ||
const k4 = <Tag key="1"><div></div></Tag>; | ||
~~~ | ||
!!! error TS2322: Type '{ children: Element; key: string; }' is not assignable to type 'IntrinsicAttributes'. | ||
!!! error TS2322: Property 'children' does not exist on type 'IntrinsicAttributes'. | ||
const k5 = <Tag key="1"><div></div><div></div></Tag>; | ||
~~~ | ||
!!! error TS2322: Type '{ children: Element[]; key: string; }' is not assignable to type 'IntrinsicAttributes'. | ||
!!! error TS2322: Property 'children' does not exist on type 'IntrinsicAttributes'. | ||
|
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,27 @@ | ||
//// [file.tsx] | ||
import React = require('react'); | ||
|
||
const Tag = (x: {}) => <div></div>; | ||
|
||
// OK | ||
const k1 = <Tag />; | ||
const k2 = <Tag></Tag>; | ||
|
||
// Not OK (excess children) | ||
const k3 = <Tag children={<div></div>} />; | ||
const k4 = <Tag key="1"><div></div></Tag>; | ||
const k5 = <Tag key="1"><div></div><div></div></Tag>; | ||
|
||
|
||
//// [file.jsx] | ||
"use strict"; | ||
exports.__esModule = true; | ||
var React = require("react"); | ||
var Tag = function (x) { return <div></div>; }; | ||
// OK | ||
var k1 = <Tag />; | ||
var k2 = <Tag></Tag>; | ||
// Not OK (excess children) | ||
var k3 = <Tag children={<div></div>}/>; | ||
var k4 = <Tag key="1"><div></div></Tag>; | ||
var k5 = <Tag key="1"><div></div><div></div></Tag>; |
46 changes: 46 additions & 0 deletions
46
tests/baselines/reference/checkJsxChildrenProperty15.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,46 @@ | ||
=== tests/cases/conformance/jsx/file.tsx === | ||
import React = require('react'); | ||
>React : Symbol(React, Decl(file.tsx, 0, 0)) | ||
|
||
const Tag = (x: {}) => <div></div>; | ||
>Tag : Symbol(Tag, Decl(file.tsx, 2, 5)) | ||
>x : Symbol(x, Decl(file.tsx, 2, 13)) | ||
>div : Symbol(JSX.IntrinsicElements.div, Decl(react.d.ts, 2400, 45)) | ||
>div : Symbol(JSX.IntrinsicElements.div, Decl(react.d.ts, 2400, 45)) | ||
|
||
// OK | ||
const k1 = <Tag />; | ||
>k1 : Symbol(k1, Decl(file.tsx, 5, 5)) | ||
>Tag : Symbol(Tag, Decl(file.tsx, 2, 5)) | ||
|
||
const k2 = <Tag></Tag>; | ||
>k2 : Symbol(k2, Decl(file.tsx, 6, 5)) | ||
>Tag : Symbol(Tag, Decl(file.tsx, 2, 5)) | ||
>Tag : Symbol(Tag, Decl(file.tsx, 2, 5)) | ||
|
||
// Not OK (excess children) | ||
const k3 = <Tag children={<div></div>} />; | ||
>k3 : Symbol(k3, Decl(file.tsx, 9, 5)) | ||
>Tag : Symbol(Tag, Decl(file.tsx, 2, 5)) | ||
>children : Symbol(children, Decl(file.tsx, 9, 15)) | ||
>div : Symbol(JSX.IntrinsicElements.div, Decl(react.d.ts, 2400, 45)) | ||
>div : Symbol(JSX.IntrinsicElements.div, Decl(react.d.ts, 2400, 45)) | ||
|
||
const k4 = <Tag key="1"><div></div></Tag>; | ||
>k4 : Symbol(k4, Decl(file.tsx, 10, 5)) | ||
>Tag : Symbol(Tag, Decl(file.tsx, 2, 5)) | ||
>key : Symbol(key, Decl(file.tsx, 10, 15)) | ||
>div : Symbol(JSX.IntrinsicElements.div, Decl(react.d.ts, 2400, 45)) | ||
>div : Symbol(JSX.IntrinsicElements.div, Decl(react.d.ts, 2400, 45)) | ||
>Tag : Symbol(Tag, Decl(file.tsx, 2, 5)) | ||
|
||
const k5 = <Tag key="1"><div></div><div></div></Tag>; | ||
>k5 : Symbol(k5, Decl(file.tsx, 11, 5)) | ||
>Tag : Symbol(Tag, Decl(file.tsx, 2, 5)) | ||
>key : Symbol(key, Decl(file.tsx, 11, 15)) | ||
>div : Symbol(JSX.IntrinsicElements.div, Decl(react.d.ts, 2400, 45)) | ||
>div : Symbol(JSX.IntrinsicElements.div, Decl(react.d.ts, 2400, 45)) | ||
>div : Symbol(JSX.IntrinsicElements.div, Decl(react.d.ts, 2400, 45)) | ||
>div : Symbol(JSX.IntrinsicElements.div, Decl(react.d.ts, 2400, 45)) | ||
>Tag : Symbol(Tag, Decl(file.tsx, 2, 5)) | ||
|
57 changes: 57 additions & 0 deletions
57
tests/baselines/reference/checkJsxChildrenProperty15.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,57 @@ | ||
=== tests/cases/conformance/jsx/file.tsx === | ||
import React = require('react'); | ||
>React : typeof React | ||
|
||
const Tag = (x: {}) => <div></div>; | ||
>Tag : (x: {}) => JSX.Element | ||
>(x: {}) => <div></div> : (x: {}) => JSX.Element | ||
>x : {} | ||
><div></div> : JSX.Element | ||
>div : any | ||
>div : any | ||
|
||
// OK | ||
const k1 = <Tag />; | ||
>k1 : JSX.Element | ||
><Tag /> : JSX.Element | ||
>Tag : (x: {}) => JSX.Element | ||
|
||
const k2 = <Tag></Tag>; | ||
>k2 : JSX.Element | ||
><Tag></Tag> : JSX.Element | ||
>Tag : (x: {}) => JSX.Element | ||
>Tag : (x: {}) => JSX.Element | ||
|
||
// Not OK (excess children) | ||
const k3 = <Tag children={<div></div>} />; | ||
>k3 : JSX.Element | ||
><Tag children={<div></div>} /> : JSX.Element | ||
>Tag : (x: {}) => JSX.Element | ||
>children : JSX.Element | ||
><div></div> : JSX.Element | ||
>div : any | ||
>div : any | ||
|
||
const k4 = <Tag key="1"><div></div></Tag>; | ||
>k4 : JSX.Element | ||
><Tag key="1"><div></div></Tag> : JSX.Element | ||
>Tag : (x: {}) => JSX.Element | ||
>key : string | ||
><div></div> : JSX.Element | ||
>div : any | ||
>div : any | ||
>Tag : (x: {}) => JSX.Element | ||
|
||
const k5 = <Tag key="1"><div></div><div></div></Tag>; | ||
>k5 : JSX.Element | ||
><Tag key="1"><div></div><div></div></Tag> : JSX.Element | ||
>Tag : (x: {}) => JSX.Element | ||
>key : string | ||
><div></div> : JSX.Element | ||
>div : any | ||
>div : any | ||
><div></div> : JSX.Element | ||
>div : any | ||
>div : any | ||
>Tag : (x: {}) => JSX.Element | ||
|
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
18 changes: 18 additions & 0 deletions
18
tests/cases/conformance/jsx/checkJsxChildrenProperty15.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,18 @@ | ||
// @filename: file.tsx | ||
// @jsx: preserve | ||
// @noLib: true | ||
// @skipLibCheck: true | ||
// @libFiles: react.d.ts,lib.d.ts | ||
|
||
import React = require('react'); | ||
|
||
const Tag = (x: {}) => <div></div>; | ||
|
||
// OK | ||
const k1 = <Tag />; | ||
const k2 = <Tag></Tag>; | ||
|
||
// Not OK (excess children) | ||
const k3 = <Tag children={<div></div>} />; | ||
const k4 = <Tag key="1"><div></div></Tag>; | ||
const k5 = <Tag key="1"><div></div><div></div></Tag>; |
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.
You might be thinking "why is there a new error here?" well, because the signature this was compatible with is now eliminated by the excess child prop, and a
string
child prop isn't compatible with any of the other signatures~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.
Oh, wow, bonus bugfix 😄
The error is definitely confusing, though, but such is how overload resolution goes... it's always on the last overload, not on the "almost, but not quite, more specific"