Fix bug #3737 (exported JSX classes props not validated)

This commit is contained in:
Ryan Cavanaugh
2015-07-07 12:46:58 -07:00
parent f682980216
commit 311d20fa99
6 changed files with 199 additions and 11 deletions

View File

@@ -0,0 +1,31 @@
tests/cases/conformance/jsx/file.tsx(9,14): error TS2322: Type 'number' is not assignable to type 'string'.
==== tests/cases/conformance/jsx/react.d.ts (0 errors) ====
declare module JSX {
interface Element { }
interface IntrinsicElements {
}
interface ElementAttributesProperty {
props;
}
}
interface Props {
foo: string;
}
==== tests/cases/conformance/jsx/file.tsx (1 errors) ====
export class MyComponent {
render() {
}
props: { foo: string; }
}
<MyComponent foo="bar" />; // ok
<MyComponent foo={0} />; // should be an error
~~~~~~~
!!! error TS2322: Type 'number' is not assignable to type 'string'.

View File

@@ -0,0 +1,42 @@
//// [tests/cases/conformance/jsx/tsxAttributeResolution9.tsx] ////
//// [react.d.ts]
declare module JSX {
interface Element { }
interface IntrinsicElements {
}
interface ElementAttributesProperty {
props;
}
}
interface Props {
foo: string;
}
//// [file.tsx]
export class MyComponent {
render() {
}
props: { foo: string; }
}
<MyComponent foo="bar" />; // ok
<MyComponent foo={0} />; // should be an error
//// [file.jsx]
define(["require", "exports"], function (require, exports) {
var MyComponent = (function () {
function MyComponent() {
}
MyComponent.prototype.render = function () {
};
return MyComponent;
})();
exports.MyComponent = MyComponent;
<MyComponent foo="bar"/>; // ok
<MyComponent foo={0}/>; // should be an error
});

View File

@@ -0,0 +1,45 @@
=== tests/cases/conformance/jsx/tsxAttributeResolution9.tsx ===
declare module JSX {
>JSX : Symbol(JSX, Decl(tsxAttributeResolution9.tsx, 0, 0))
interface Element { }
>Element : Symbol(Element, Decl(tsxAttributeResolution9.tsx, 0, 20))
interface IntrinsicElements {
>IntrinsicElements : Symbol(IntrinsicElements, Decl(tsxAttributeResolution9.tsx, 1, 22))
}
interface ElementAttributesProperty {
>ElementAttributesProperty : Symbol(ElementAttributesProperty, Decl(tsxAttributeResolution9.tsx, 3, 2))
props;
>props : Symbol(props, Decl(tsxAttributeResolution9.tsx, 4, 38))
}
}
interface Props {
>Props : Symbol(Props, Decl(tsxAttributeResolution9.tsx, 7, 1))
foo: string;
>foo : Symbol(foo, Decl(tsxAttributeResolution9.tsx, 9, 17))
}
export class MyComponent {
>MyComponent : Symbol(MyComponent, Decl(tsxAttributeResolution9.tsx, 11, 1))
render() {
>render : Symbol(render, Decl(tsxAttributeResolution9.tsx, 13, 26))
}
props: { foo: string; }
>props : Symbol(props, Decl(tsxAttributeResolution9.tsx, 15, 3))
>foo : Symbol(foo, Decl(tsxAttributeResolution9.tsx, 17, 10))
}
<MyComponent foo="bar" />; // ok
>MyComponent : Symbol(MyComponent, Decl(tsxAttributeResolution9.tsx, 11, 1))
>foo : Symbol(unknown)
<MyComponent foo={0} />; // should be an error
>MyComponent : Symbol(MyComponent, Decl(tsxAttributeResolution9.tsx, 11, 1))
>foo : Symbol(unknown)

View File

@@ -0,0 +1,47 @@
=== tests/cases/conformance/jsx/tsxAttributeResolution9.tsx ===
declare module JSX {
>JSX : any
interface Element { }
>Element : Element
interface IntrinsicElements {
>IntrinsicElements : IntrinsicElements
}
interface ElementAttributesProperty {
>ElementAttributesProperty : ElementAttributesProperty
props;
>props : any
}
}
interface Props {
>Props : Props
foo: string;
>foo : string
}
export class MyComponent {
>MyComponent : MyComponent
render() {
>render : () => void
}
props: { foo: string; }
>props : { foo: string; }
>foo : string
}
<MyComponent foo="bar" />; // ok
><MyComponent foo="bar" /> : any
>MyComponent : typeof MyComponent
>foo : any
<MyComponent foo={0} />; // should be an error
><MyComponent foo={0} /> : any
>MyComponent : typeof MyComponent
>foo : any

View File

@@ -0,0 +1,27 @@
//@jsx: preserve
//@module: amd
//@filename: react.d.ts
declare module JSX {
interface Element { }
interface IntrinsicElements {
}
interface ElementAttributesProperty {
props;
}
}
interface Props {
foo: string;
}
//@filename: file.tsx
export class MyComponent {
render() {
}
props: { foo: string; }
}
<MyComponent foo="bar" />; // ok
<MyComponent foo={0} />; // should be an error