Address code review

This commit is contained in:
Kanchalai Tanglertsampan 2017-02-03 10:54:15 -08:00
parent aea551c3b8
commit 56f31c3266
6 changed files with 4 additions and 139 deletions

View file

@ -40,7 +40,7 @@ tests/cases/conformance/types/contextualTypes/jsxAttributes/file.tsx(37,25): err
return this._buildMainButton(props);
}
const b0 = <MainButton {...{onClick: (k) => {console.log(k)}}} extra />; // k has type any
const b0 = <MainButton {...{onClick: (k) => {console.log(k)}}} extra />; // k has type "left" | "right"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2322: Type '{ extra: true; onClick: (k: "left" | "right") => void; }' is not assignable to type 'IntrinsicAttributes & LinkProps'.
!!! error TS2322: Property 'extra' does not exist on type 'IntrinsicAttributes & LinkProps'.

View file

@ -26,7 +26,7 @@ export function MainButton(props: ButtonProps | LinkProps): JSX.Element {
return this._buildMainButton(props);
}
const b0 = <MainButton {...{onClick: (k) => {console.log(k)}}} extra />; // k has type any
const b0 = <MainButton {...{onClick: (k) => {console.log(k)}}} extra />; // k has type "left" | "right"
const b2 = <MainButton onClick={(k)=>{console.log(k)}} extra />; // k has type "left" | "right"
const b3 = <MainButton {...{goTo:"home"}} extra />; // goTo has type"home" | "contact"
const b4 = <MainButton goTo="home" extra />; // goTo has type "home" | "contact"
@ -49,7 +49,7 @@ define(["require", "exports", "react"], function (require, exports, React) {
return this._buildMainButton(props);
}
exports.MainButton = MainButton;
var b0 = <MainButton {...{ onClick: function (k) { console.log(k); } }} extra/>; // k has type any
var b0 = <MainButton {...{ onClick: function (k) { console.log(k); } }} extra/>; // k has type "left" | "right"
var b2 = <MainButton onClick={function (k) { console.log(k); }} extra/>; // k has type "left" | "right"
var b3 = <MainButton {...{ goTo: "home" }} extra/>; // goTo has type"home" | "contact"
var b4 = <MainButton goTo="home" extra/>; // goTo has type "home" | "contact"

View file

@ -1,62 +0,0 @@
=== tests/cases/conformance/jsx/file.tsx ===
import React = require('react');
>React : Symbol(React, Decl(file.tsx, 0, 0))
type TextProps = { editable: false }
>TextProps : Symbol(TextProps, Decl(file.tsx, 1, 32))
>editable : Symbol(editable, Decl(file.tsx, 3, 18))
| { editable: true, onEdit: (newText: string) => void };
>editable : Symbol(editable, Decl(file.tsx, 4, 18))
>onEdit : Symbol(onEdit, Decl(file.tsx, 4, 34))
>newText : Symbol(newText, Decl(file.tsx, 4, 44))
class TextComponent extends React.Component<TextProps, {}> {
>TextComponent : Symbol(TextComponent, Decl(file.tsx, 4, 71))
>React.Component : Symbol(React.Component, Decl(react.d.ts, 158, 55))
>React : Symbol(React, Decl(file.tsx, 0, 0))
>Component : Symbol(React.Component, Decl(react.d.ts, 158, 55))
>TextProps : Symbol(TextProps, Decl(file.tsx, 1, 32))
render() {
>render : Symbol(TextComponent.render, Decl(file.tsx, 6, 60))
return <span>Some Text..</span>;
>span : Symbol(JSX.IntrinsicElements.span, Decl(react.d.ts, 2458, 51))
>span : Symbol(JSX.IntrinsicElements.span, Decl(react.d.ts, 2458, 51))
}
}
// OK
const textPropsFalse: TextProps = {
>textPropsFalse : Symbol(textPropsFalse, Decl(file.tsx, 13, 5))
>TextProps : Symbol(TextProps, Decl(file.tsx, 1, 32))
editable: false
>editable : Symbol(editable, Decl(file.tsx, 13, 35))
};
let y1 = <TextComponent {...textPropsFalse} />
>y1 : Symbol(y1, Decl(file.tsx, 17, 3))
>TextComponent : Symbol(TextComponent, Decl(file.tsx, 4, 71))
>textPropsFalse : Symbol(textPropsFalse, Decl(file.tsx, 13, 5))
const textPropsTrue: TextProps = {
>textPropsTrue : Symbol(textPropsTrue, Decl(file.tsx, 19, 5))
>TextProps : Symbol(TextProps, Decl(file.tsx, 1, 32))
editable: true,
>editable : Symbol(editable, Decl(file.tsx, 19, 34))
onEdit: () => {}
>onEdit : Symbol(onEdit, Decl(file.tsx, 20, 19))
};
let y2 = <TextComponent {...textPropsTrue} />
>y2 : Symbol(y2, Decl(file.tsx, 24, 3))
>TextComponent : Symbol(TextComponent, Decl(file.tsx, 4, 71))
>textPropsTrue : Symbol(textPropsTrue, Decl(file.tsx, 19, 5))

View file

@ -1,72 +0,0 @@
=== tests/cases/conformance/jsx/file.tsx ===
import React = require('react');
>React : typeof React
type TextProps = { editable: false }
>TextProps : { editable: false; } | { editable: true; onEdit: (newText: string) => void; }
>editable : false
>false : false
| { editable: true, onEdit: (newText: string) => void };
>editable : true
>true : true
>onEdit : (newText: string) => void
>newText : string
class TextComponent extends React.Component<TextProps, {}> {
>TextComponent : TextComponent
>React.Component : React.Component<{ editable: false; } | { editable: true; onEdit: (newText: string) => void; }, {}>
>React : typeof React
>Component : typeof React.Component
>TextProps : { editable: false; } | { editable: true; onEdit: (newText: string) => void; }
render() {
>render : () => JSX.Element
return <span>Some Text..</span>;
><span>Some Text..</span> : JSX.Element
>span : any
>span : any
}
}
// OK
const textPropsFalse: TextProps = {
>textPropsFalse : { editable: false; } | { editable: true; onEdit: (newText: string) => void; }
>TextProps : { editable: false; } | { editable: true; onEdit: (newText: string) => void; }
>{ editable: false} : { editable: false; }
editable: false
>editable : boolean
>false : false
};
let y1 = <TextComponent {...textPropsFalse} />
>y1 : JSX.Element
><TextComponent {...textPropsFalse} /> : JSX.Element
>TextComponent : typeof TextComponent
>textPropsFalse : { editable: false; }
const textPropsTrue: TextProps = {
>textPropsTrue : { editable: false; } | { editable: true; onEdit: (newText: string) => void; }
>TextProps : { editable: false; } | { editable: true; onEdit: (newText: string) => void; }
>{ editable: true, onEdit: () => {}} : { editable: true; onEdit: () => void; }
editable: true,
>editable : boolean
>true : true
onEdit: () => {}
>onEdit : () => void
>() => {} : () => void
};
let y2 = <TextComponent {...textPropsTrue} />
>y2 : JSX.Element
><TextComponent {...textPropsTrue} /> : JSX.Element
>TextComponent : typeof TextComponent
>textPropsTrue : { editable: true; onEdit: (newText: string) => void; }

View file

@ -30,7 +30,7 @@ export function MainButton(props: ButtonProps | LinkProps): JSX.Element {
return this._buildMainButton(props);
}
const b0 = <MainButton {...{onClick: (k) => {console.log(k)}}} extra />; // k has type any
const b0 = <MainButton {...{onClick: (k) => {console.log(k)}}} extra />; // k has type "left" | "right"
const b2 = <MainButton onClick={(k)=>{console.log(k)}} extra />; // k has type "left" | "right"
const b3 = <MainButton {...{goTo:"home"}} extra />; // goTo has type"home" | "contact"
const b4 = <MainButton goTo="home" extra />; // goTo has type "home" | "contact"

View file

@ -31,7 +31,6 @@
//// let e1 = <MainButton/*1*/ /*2*/
goTo.marker("1");
// The second overload is chosen because the first doesn't get selected by choose overload as it has incorrect arity
verify.signatureHelpCountIs(2);
verify.currentSignatureHelpIs("MainButton(buttonProps: ButtonProps): any");
verify.currentParameterSpanIs("buttonProps: ButtonProps");