- 
                Notifications
    You must be signed in to change notification settings 
- Fork 13.1k
[Master] Type checking JSX children #15160
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
      
      
    
  
     Merged
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            24 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      b3846bf
              
                Wip - type checking JSX children
              
              
                 f86a730
              
                Consider whitespace that won't be emitted to be different kind so tha…
              
              
                 8e2dd38
              
                Use JSX Attributes to contextually type children property
              
              
                 17417e9
              
                Format checker
              
              
                 4562fd0
              
                Store scanning information whether JSXText is just an all whitespaces
              
              
                 c1ea303
              
                wip-fixing consuming whitespace in children
              
              
                 4fa2312
              
                Fixing consuming whitespace in children
              
              
                 f099046
              
                Add tests
              
              
                 eb0ad7f
              
                update baselines
              
              
                 e5b95fc
              
                Merge branch 'master-jsxChildren' of https://github.com/Microsoft/Typ…
              
              
                 012f459
              
                Fix linting error
              
              
                 58e2189
              
                Add tests and update baselines
              
              
                 bb8bab3
              
                Remove a flag indicating the children is synthesized..We will give an…
              
              
                 c778a48
              
                Read "children" property from react DTS file
              
              
                 dbf2a96
              
                Update tests and baselines
              
              
                 9a23b75
              
                Update baselines and tests (2)
              
              
                 7829cba
              
                Fix linting error
              
              
                 d290cf7
              
                Update error message to use variable name for "children"
              
              
                 f6f0813
              
                Merge branch 'master' into master-jsxChildren
              
              
                 c13383a
              
                Fix baselines and linting error from merging with master
              
              
                 e9cd3ad
              
                Change how we look up children attribute from react.d.ts
              
              
                 b7a30c1
              
                Update tests and baselines
              
              
                 e03be45
              
                Fix spelling and add comment
              
              
                 e7e13ec
              
                Fix linting
              
              
                 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
Large diffs are not rendered by default.
      
      Oops, something went wrong.
      
    
  
  
    
      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
    
  
  
    
              
  
    
      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
    
  
  
    
              
  
    
      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
    
  
  
    
              
  
    
      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
    
  
  
    
              
  
    
      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,39 @@ | ||
| //// [file.tsx] | ||
| import React = require('react'); | ||
|  | ||
| interface Prop { | ||
| a: number, | ||
| b: string, | ||
| children: string | JSX.Element | ||
| } | ||
|  | ||
| function Comp(p: Prop) { | ||
| return <div>{p.b}</div>; | ||
| } | ||
|  | ||
| // OK | ||
| let k = <Comp a={10} b="hi" children ="lol" />; | ||
| let k1 = | ||
| <Comp a={10} b="hi"> | ||
| hi hi hi! | ||
| </Comp>; | ||
| let k2 = | ||
| <Comp a={10} b="hi"> | ||
| <div>hi hi hi!</div> | ||
| </Comp>; | ||
|  | ||
| //// [file.jsx] | ||
| "use strict"; | ||
| exports.__esModule = true; | ||
| var React = require("react"); | ||
| function Comp(p) { | ||
| return <div>{p.b}</div>; | ||
| } | ||
| // OK | ||
| var k = <Comp a={10} b="hi" children="lol"/>; | ||
| var k1 = <Comp a={10} b="hi"> | ||
| hi hi hi! | ||
| </Comp>; | ||
| var k2 = <Comp a={10} b="hi"> | ||
| <div>hi hi hi!</div> | ||
| </Comp>; | 
        
          
          
            67 changes: 67 additions & 0 deletions
          
          67 
        
  tests/baselines/reference/checkJsxChildrenProperty1.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,67 @@ | ||
| === tests/cases/conformance/jsx/file.tsx === | ||
| import React = require('react'); | ||
| >React : Symbol(React, Decl(file.tsx, 0, 0)) | ||
|  | ||
| interface Prop { | ||
| >Prop : Symbol(Prop, Decl(file.tsx, 0, 32)) | ||
|  | ||
| a: number, | ||
| >a : Symbol(Prop.a, Decl(file.tsx, 2, 16)) | ||
|  | ||
| b: string, | ||
| >b : Symbol(Prop.b, Decl(file.tsx, 3, 14)) | ||
|  | ||
| children: string | JSX.Element | ||
| >children : Symbol(Prop.children, Decl(file.tsx, 4, 14)) | ||
| >JSX : Symbol(JSX, Decl(react.d.ts, 2352, 1)) | ||
| >Element : Symbol(JSX.Element, Decl(react.d.ts, 2355, 27)) | ||
| } | ||
|  | ||
| function Comp(p: Prop) { | ||
| >Comp : Symbol(Comp, Decl(file.tsx, 6, 1)) | ||
| >p : Symbol(p, Decl(file.tsx, 8, 14)) | ||
| >Prop : Symbol(Prop, Decl(file.tsx, 0, 32)) | ||
|  | ||
| return <div>{p.b}</div>; | ||
| >div : Symbol(JSX.IntrinsicElements.div, Decl(react.d.ts, 2399, 45)) | ||
| >p.b : Symbol(Prop.b, Decl(file.tsx, 3, 14)) | ||
| >p : Symbol(p, Decl(file.tsx, 8, 14)) | ||
| >b : Symbol(Prop.b, Decl(file.tsx, 3, 14)) | ||
| >div : Symbol(JSX.IntrinsicElements.div, Decl(react.d.ts, 2399, 45)) | ||
| } | ||
|  | ||
| // OK | ||
| let k = <Comp a={10} b="hi" children ="lol" />; | ||
| >k : Symbol(k, Decl(file.tsx, 13, 3)) | ||
| >Comp : Symbol(Comp, Decl(file.tsx, 6, 1)) | ||
| >a : Symbol(a, Decl(file.tsx, 13, 13)) | ||
| >b : Symbol(b, Decl(file.tsx, 13, 20)) | ||
| >children : Symbol(children, Decl(file.tsx, 13, 27)) | ||
|  | ||
| let k1 = | ||
| >k1 : Symbol(k1, Decl(file.tsx, 14, 3)) | ||
|  | ||
| <Comp a={10} b="hi"> | ||
| >Comp : Symbol(Comp, Decl(file.tsx, 6, 1)) | ||
| >a : Symbol(a, Decl(file.tsx, 15, 9)) | ||
| >b : Symbol(b, Decl(file.tsx, 15, 16)) | ||
|  | ||
| hi hi hi! | ||
| </Comp>; | ||
| >Comp : Symbol(Comp, Decl(file.tsx, 6, 1)) | ||
|  | ||
| let k2 = | ||
| >k2 : Symbol(k2, Decl(file.tsx, 18, 3)) | ||
|  | ||
| <Comp a={10} b="hi"> | ||
| >Comp : Symbol(Comp, Decl(file.tsx, 6, 1)) | ||
| >a : Symbol(a, Decl(file.tsx, 19, 9)) | ||
| >b : Symbol(b, Decl(file.tsx, 19, 16)) | ||
|  | ||
| <div>hi hi hi!</div> | ||
| >div : Symbol(JSX.IntrinsicElements.div, Decl(react.d.ts, 2399, 45)) | ||
| >div : Symbol(JSX.IntrinsicElements.div, Decl(react.d.ts, 2399, 45)) | ||
|  | ||
| </Comp>; | ||
| >Comp : Symbol(Comp, Decl(file.tsx, 6, 1)) | ||
|  | 
  
    
      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,75 @@ | ||
| === tests/cases/conformance/jsx/file.tsx === | ||
| import React = require('react'); | ||
| >React : typeof React | ||
|  | ||
| interface Prop { | ||
| >Prop : Prop | ||
|  | ||
| a: number, | ||
| >a : number | ||
|  | ||
| b: string, | ||
| >b : string | ||
|  | ||
| children: string | JSX.Element | ||
| >children : string | JSX.Element | ||
| >JSX : any | ||
| >Element : JSX.Element | ||
| } | ||
|  | ||
| function Comp(p: Prop) { | ||
| >Comp : (p: Prop) => JSX.Element | ||
| >p : Prop | ||
| >Prop : Prop | ||
|  | ||
| return <div>{p.b}</div>; | ||
| ><div>{p.b}</div> : JSX.Element | ||
| >div : any | ||
| >p.b : string | ||
| >p : Prop | ||
| >b : string | ||
| >div : any | ||
| } | ||
|  | ||
| // OK | ||
| let k = <Comp a={10} b="hi" children ="lol" />; | ||
| >k : JSX.Element | ||
| ><Comp a={10} b="hi" children ="lol" /> : JSX.Element | ||
| >Comp : (p: Prop) => JSX.Element | ||
| >a : number | ||
| >10 : 10 | ||
| >b : string | ||
| >children : string | ||
|  | ||
| let k1 = | ||
| >k1 : JSX.Element | ||
|  | ||
| <Comp a={10} b="hi"> | ||
| ><Comp a={10} b="hi"> hi hi hi! </Comp> : JSX.Element | ||
| >Comp : (p: Prop) => JSX.Element | ||
| >a : number | ||
| >10 : 10 | ||
| >b : string | ||
|  | ||
| hi hi hi! | ||
| </Comp>; | ||
| >Comp : (p: Prop) => JSX.Element | ||
|  | ||
| let k2 = | ||
| >k2 : JSX.Element | ||
|  | ||
| <Comp a={10} b="hi"> | ||
| ><Comp a={10} b="hi"> <div>hi hi hi!</div> </Comp> : JSX.Element | ||
| >Comp : (p: Prop) => JSX.Element | ||
| >a : number | ||
| >10 : 10 | ||
| >b : string | ||
|  | ||
| <div>hi hi hi!</div> | ||
| ><div>hi hi hi!</div> : JSX.Element | ||
| >div : any | ||
| >div : any | ||
|  | ||
| </Comp>; | ||
| >Comp : (p: Prop) => 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
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| //// [file.tsx] | ||
| declare module JSX { | ||
| interface Element { } | ||
| interface ElementAttributesProperty { props: {} } | ||
| interface IntrinsicElements { | ||
| div: any; | ||
| h2: any; | ||
| h1: any; | ||
| } | ||
| } | ||
|  | ||
| class Button { | ||
| props: {} | ||
| render() { | ||
| return (<div>My Button</div>) | ||
| } | ||
| } | ||
|  | ||
| // OK | ||
| let k1 = <div> <h2> Hello </h2> <h1> world </h1></div>; | ||
| let k2 = <div> <h2> Hello </h2> {(user: any) => <h2>{user.name}</h2>}</div>; | ||
| let k3 = <div> {1} {"That is a number"} </div>; | ||
| let k4 = <Button> <h2> Hello </h2> </Button>; | ||
|  | ||
| //// [file.jsx] | ||
| var Button = (function () { | ||
| function Button() { | ||
| } | ||
| Button.prototype.render = function () { | ||
| return (<div>My Button</div>); | ||
| }; | ||
| return Button; | ||
| }()); | ||
| // OK | ||
| var k1 = <div> <h2> Hello </h2> <h1> world </h1></div>; | ||
| var k2 = <div> <h2> Hello </h2> {function (user) { return <h2>{user.name}</h2>; }}</div>; | ||
| var k3 = <div> {1} {"That is a number"} </div>; | ||
| var k4 = <Button> <h2> Hello </h2> </Button>; | 
      
      Oops, something went wrong.
        
    
  
  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.
Why the rename?
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.
Because it is not just WhiteSpace but Whitespace and empty line.