declare namespace JSX JSX {
interface ElementClass {
render: any;
}
}
class MyComponent {
render() {}
}
function MyFactoryFunction() {
return { render: () => {} }
}
; // ok
; // ok
class NotAValidComponent {}
function NotAValidFactoryFunction() {
return {};
}
; // error
; // error
class MyComponent {
render() {}
}
// use a construct signature
var myComponent = new MyComponent();
function MyFactoryFunction() {
return {
render: () => {
}
}
}
// use a call signature
var myComponent = MyFactoryFunction();
declare namespace JSX {
interface ElementAttributesProperty {
props; // specify the property name to use
}
}
class MyComponent {
// specify the property on the element instance type
props: {
foo?: string;
}
}
// element attributes type for 'MyComponent' is '{foo?: string}'
;
declare namespace JSX {
interface IntrinsicElements {
foo: { requiredProp: string; optionalProp?: number }
}
}
; // ok
; // ok
; // error, requiredProp is missing
; // error, requiredProp should be a string
; // error, unknownProp does not exist
; // ok, because 'some-unknown-prop' is not a valid identifier
var a =
{["foo", "bar"].map(function (i) { return {i / 2} })}