-
Notifications
You must be signed in to change notification settings - Fork 12.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Baseline arity checks for jsx sfc tags (#36643)
Finish comment PR feedback
- Loading branch information
Showing
8 changed files
with
363 additions
and
7 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
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
35 changes: 35 additions & 0 deletions
35
tests/baselines/reference/jsxIssuesErrorWhenTagExpectsTooManyArguments.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,35 @@ | ||
tests/cases/compiler/jsxIssuesErrorWhenTagExpectsTooManyArguments.tsx(19,12): error TS6229: Tag 'MyComp4' expects at least '4' arguments, but the JSX factory 'React.createElement' provides at most '2'. | ||
tests/cases/compiler/jsxIssuesErrorWhenTagExpectsTooManyArguments.tsx(20,12): error TS6229: Tag 'MyComp3' expects at least '3' arguments, but the JSX factory 'React.createElement' provides at most '2'. | ||
|
||
|
||
==== tests/cases/compiler/jsxIssuesErrorWhenTagExpectsTooManyArguments.tsx (2 errors) ==== | ||
/// <reference path="/.lib/react16.d.ts" /> | ||
|
||
import * as React from "react"; | ||
|
||
interface MyProps { | ||
x: number; | ||
} | ||
|
||
function MyComp4(props: MyProps, context: any, bad: any, verybad: any) { | ||
return <div></div>; | ||
} | ||
function MyComp3(props: MyProps, context: any, bad: any) { | ||
return <div></div>; | ||
} | ||
function MyComp2(props: MyProps, context: any) { | ||
return <div></div> | ||
} | ||
|
||
const a = <MyComp4 x={2}/>; // using `MyComp` as a component should error - it expects more arguments than react provides | ||
~~~~~~~ | ||
!!! error TS6229: Tag 'MyComp4' expects at least '4' arguments, but the JSX factory 'React.createElement' provides at most '2'. | ||
!!! related TS2728 tests/cases/compiler/jsxIssuesErrorWhenTagExpectsTooManyArguments.tsx:9:10: 'MyComp4' is declared here. | ||
const b = <MyComp3 x={2}/>; // using `MyComp` as a component should error - it expects more arguments than react provides | ||
~~~~~~~ | ||
!!! error TS6229: Tag 'MyComp3' expects at least '3' arguments, but the JSX factory 'React.createElement' provides at most '2'. | ||
!!! related TS2728 tests/cases/compiler/jsxIssuesErrorWhenTagExpectsTooManyArguments.tsx:12:10: 'MyComp3' is declared here. | ||
const c = <MyComp2 x={2}/>; // Should be OK, `context` is allowed, per react rules | ||
|
||
declare function MyTagWithOptionalNonJSXBits(props: MyProps, context: any, nonReactArg?: string): JSX.Element; | ||
const d = <MyTagWithOptionalNonJSXBits x={2} />; // Technically OK, but probably questionable |
44 changes: 44 additions & 0 deletions
44
tests/baselines/reference/jsxIssuesErrorWhenTagExpectsTooManyArguments.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 @@ | ||
//// [jsxIssuesErrorWhenTagExpectsTooManyArguments.tsx] | ||
/// <reference path="/.lib/react16.d.ts" /> | ||
|
||
import * as React from "react"; | ||
|
||
interface MyProps { | ||
x: number; | ||
} | ||
|
||
function MyComp4(props: MyProps, context: any, bad: any, verybad: any) { | ||
return <div></div>; | ||
} | ||
function MyComp3(props: MyProps, context: any, bad: any) { | ||
return <div></div>; | ||
} | ||
function MyComp2(props: MyProps, context: any) { | ||
return <div></div> | ||
} | ||
|
||
const a = <MyComp4 x={2}/>; // using `MyComp` as a component should error - it expects more arguments than react provides | ||
const b = <MyComp3 x={2}/>; // using `MyComp` as a component should error - it expects more arguments than react provides | ||
const c = <MyComp2 x={2}/>; // Should be OK, `context` is allowed, per react rules | ||
declare function MyTagWithOptionalNonJSXBits(props: MyProps, context: any, nonReactArg?: string): JSX.Element; | ||
const d = <MyTagWithOptionalNonJSXBits x={2} />; // Technically OK, but probably questionable | ||
//// [jsxIssuesErrorWhenTagExpectsTooManyArguments.js] | ||
"use strict"; | ||
/// <reference path="react16.d.ts" /> | ||
exports.__esModule = true; | ||
var React = require("react"); | ||
function MyComp4(props, context, bad, verybad) { | ||
return React.createElement("div", null); | ||
} | ||
function MyComp3(props, context, bad) { | ||
return React.createElement("div", null); | ||
} | ||
function MyComp2(props, context) { | ||
return React.createElement("div", null); | ||
} | ||
var a = React.createElement(MyComp4, { x: 2 }); // using `MyComp` as a component should error - it expects more arguments than react provides | ||
var b = React.createElement(MyComp3, { x: 2 }); // using `MyComp` as a component should error - it expects more arguments than react provides | ||
var c = React.createElement(MyComp2, { x: 2 }); // Should be OK, `context` is allowed, per react rules | ||
var d = React.createElement(MyTagWithOptionalNonJSXBits, { x: 2 }); // Technically OK, but probably questionable |
Oops, something went wrong.