mirror of
https://github.com/hanzoai/tsgo.git
synced 2026-10-30 19:37:15 +00:00
111 lines
4.2 KiB
Plaintext
111 lines
4.2 KiB
Plaintext
//// [tests/cases/conformance/jsx/tsxStatelessFunctionComponents2.tsx] ////
|
|
|
|
=== file.tsx ===
|
|
/// <reference path="react.d.ts" />
|
|
|
|
import React = require('react');
|
|
>React : Symbol(React, Decl(file.tsx, 0, 0))
|
|
|
|
function Greet(x: {name?: string}) {
|
|
>Greet : Symbol(Greet, Decl(file.tsx, 2, 32))
|
|
>x : Symbol(x, Decl(file.tsx, 4, 15))
|
|
>name : Symbol(name, Decl(file.tsx, 4, 19))
|
|
|
|
return <div>Hello, {x}</div>;
|
|
>div : Symbol(JSX.IntrinsicElements.div, Decl(react.d.ts, 2402, 45))
|
|
>x : Symbol(x, Decl(file.tsx, 4, 15))
|
|
>div : Symbol(JSX.IntrinsicElements.div, Decl(react.d.ts, 2402, 45))
|
|
}
|
|
|
|
class BigGreeter extends React.Component<{ name?: string }, {}> {
|
|
>BigGreeter : Symbol(BigGreeter, Decl(file.tsx, 6, 1))
|
|
>React.Component : Symbol(React.Component, Decl(react.d.ts, 158, 55), Decl(react.d.ts, 161, 66))
|
|
>React : Symbol(React, Decl(file.tsx, 0, 0))
|
|
>Component : Symbol(React.Component, Decl(react.d.ts, 158, 55), Decl(react.d.ts, 161, 66))
|
|
>name : Symbol(name, Decl(file.tsx, 8, 42))
|
|
|
|
render() {
|
|
>render : Symbol(BigGreeter.render, Decl(file.tsx, 8, 65))
|
|
|
|
return <div></div>;
|
|
>div : Symbol(JSX.IntrinsicElements.div, Decl(react.d.ts, 2402, 45))
|
|
>div : Symbol(JSX.IntrinsicElements.div, Decl(react.d.ts, 2402, 45))
|
|
}
|
|
greeting: string;
|
|
>greeting : Symbol(BigGreeter.greeting, Decl(file.tsx, 11, 2))
|
|
}
|
|
|
|
// OK
|
|
let a = <Greet />;
|
|
>a : Symbol(a, Decl(file.tsx, 16, 3))
|
|
>Greet : Symbol(Greet, Decl(file.tsx, 2, 32))
|
|
|
|
// OK - always valid to specify 'key'
|
|
let b = <Greet key="k" />;
|
|
>b : Symbol(b, Decl(file.tsx, 18, 3))
|
|
>Greet : Symbol(Greet, Decl(file.tsx, 2, 32))
|
|
>key : Symbol(key, Decl(file.tsx, 18, 14))
|
|
|
|
// Error - not allowed to specify 'ref' on SFCs
|
|
let c = <Greet ref="myRef" />;
|
|
>c : Symbol(c, Decl(file.tsx, 20, 3))
|
|
>Greet : Symbol(Greet, Decl(file.tsx, 2, 32))
|
|
>ref : Symbol(ref, Decl(file.tsx, 20, 14))
|
|
|
|
|
|
// OK - ref is valid for classes
|
|
let d = <BigGreeter ref={x => x.greeting.substr(10)} />;
|
|
>d : Symbol(d, Decl(file.tsx, 24, 3))
|
|
>BigGreeter : Symbol(BigGreeter, Decl(file.tsx, 6, 1))
|
|
>ref : Symbol(ref, Decl(file.tsx, 24, 19))
|
|
>x : Symbol(x, Decl(file.tsx, 24, 25))
|
|
>x.greeting.substr : Symbol(String.substr, Decl(lib.es5.d.ts, --, --))
|
|
>x.greeting : Symbol(BigGreeter.greeting, Decl(file.tsx, 11, 2))
|
|
>x : Symbol(x, Decl(file.tsx, 24, 25))
|
|
>greeting : Symbol(BigGreeter.greeting, Decl(file.tsx, 11, 2))
|
|
>substr : Symbol(String.substr, Decl(lib.es5.d.ts, --, --))
|
|
|
|
// Error ('subtr' not on string)
|
|
let e = <BigGreeter ref={x => x.greeting.subtr(10)} />;
|
|
>e : Symbol(e, Decl(file.tsx, 26, 3))
|
|
>BigGreeter : Symbol(BigGreeter, Decl(file.tsx, 6, 1))
|
|
>ref : Symbol(ref, Decl(file.tsx, 26, 19))
|
|
>x : Symbol(x, Decl(file.tsx, 26, 25))
|
|
>x.greeting : Symbol(BigGreeter.greeting, Decl(file.tsx, 11, 2))
|
|
>x : Symbol(x, Decl(file.tsx, 26, 25))
|
|
>greeting : Symbol(BigGreeter.greeting, Decl(file.tsx, 11, 2))
|
|
|
|
// Error (ref callback is contextually typed)
|
|
let f = <BigGreeter ref={x => x.notARealProperty} />;
|
|
>f : Symbol(f, Decl(file.tsx, 28, 3))
|
|
>BigGreeter : Symbol(BigGreeter, Decl(file.tsx, 6, 1))
|
|
>ref : Symbol(ref, Decl(file.tsx, 28, 19))
|
|
>x : Symbol(x, Decl(file.tsx, 28, 25))
|
|
>x : Symbol(x, Decl(file.tsx, 28, 25))
|
|
|
|
// OK - key is always valid
|
|
let g = <BigGreeter key={100} />;
|
|
>g : Symbol(g, Decl(file.tsx, 31, 3))
|
|
>BigGreeter : Symbol(BigGreeter, Decl(file.tsx, 6, 1))
|
|
>key : Symbol(key, Decl(file.tsx, 31, 19))
|
|
|
|
// OK - contextually typed intrinsic ref callback parameter
|
|
let h = <div ref={x => x.innerText} />;
|
|
>h : Symbol(h, Decl(file.tsx, 34, 3))
|
|
>div : Symbol(JSX.IntrinsicElements.div, Decl(react.d.ts, 2402, 45))
|
|
>ref : Symbol(ref, Decl(file.tsx, 34, 12))
|
|
>x : Symbol(x, Decl(file.tsx, 34, 18))
|
|
>x.innerText : Symbol(HTMLElement.innerText, Decl(lib.dom.d.ts, --, --))
|
|
>x : Symbol(x, Decl(file.tsx, 34, 18))
|
|
>innerText : Symbol(HTMLElement.innerText, Decl(lib.dom.d.ts, --, --))
|
|
|
|
// Error - property not on ontextually typed intrinsic ref callback parameter
|
|
let i = <div ref={x => x.propertyNotOnHtmlDivElement} />;
|
|
>i : Symbol(i, Decl(file.tsx, 36, 3))
|
|
>div : Symbol(JSX.IntrinsicElements.div, Decl(react.d.ts, 2402, 45))
|
|
>ref : Symbol(ref, Decl(file.tsx, 36, 12))
|
|
>x : Symbol(x, Decl(file.tsx, 36, 18))
|
|
>x : Symbol(x, Decl(file.tsx, 36, 18))
|
|
|
|
|