|
| 1 | +tests/cases/compiler/jsxComponentTypeErrors.tsx(16,11): error TS2786: 'this' cannot be used as a JSX component. |
| 2 | + Its return type '{ type: "foo" | undefined; }' is not a valid JSX element. |
| 3 | + Types of property 'type' are incompatible. |
| 4 | + Type '"foo" | undefined' is not assignable to type '"element"'. |
| 5 | + Type 'undefined' is not assignable to type '"element"'. |
| 6 | +tests/cases/compiler/jsxComponentTypeErrors.tsx(25,16): error TS2786: 'FunctionComponent' cannot be used as a JSX component. |
| 7 | + Its return type '{ type: "abc" | undefined; }' is not a valid JSX element. |
| 8 | + Types of property 'type' are incompatible. |
| 9 | + Type '"abc" | undefined' is not assignable to type '"element"'. |
| 10 | + Type 'undefined' is not assignable to type '"element"'. |
| 11 | +tests/cases/compiler/jsxComponentTypeErrors.tsx(26,16): error TS2786: 'FunctionComponent' cannot be used as a JSX component. |
| 12 | + Its return type '{ type: "abc" | undefined; }' is not a valid JSX element. |
| 13 | +tests/cases/compiler/jsxComponentTypeErrors.tsx(27,16): error TS2786: 'ClassComponent' cannot be used as a JSX component. |
| 14 | + Its instance type 'ClassComponent' is not a valid JSX element. |
| 15 | + Types of property 'type' are incompatible. |
| 16 | + Type 'string' is not assignable to type '"element-class"'. |
| 17 | +tests/cases/compiler/jsxComponentTypeErrors.tsx(28,16): error TS2786: 'MixedComponent' cannot be used as a JSX component. |
| 18 | + Its element type 'ClassComponent | { type: string | undefined; }' is not a valid JSX element. |
| 19 | + Type 'ClassComponent' is not assignable to type 'Element | ElementClass | null'. |
| 20 | + Type 'ClassComponent' is not assignable to type 'ElementClass'. |
| 21 | +tests/cases/compiler/jsxComponentTypeErrors.tsx(37,16): error TS2786: 'obj.MemberFunctionComponent' cannot be used as a JSX component. |
| 22 | + Its return type '{}' is not a valid JSX element. |
| 23 | + Property 'type' is missing in type '{}' but required in type 'Element'. |
| 24 | +tests/cases/compiler/jsxComponentTypeErrors.tsx(38,16): error TS2786: 'obj. MemberClassComponent' cannot be used as a JSX component. |
| 25 | + Its instance type 'MemberClassComponent' is not a valid JSX element. |
| 26 | + Property 'type' is missing in type 'MemberClassComponent' but required in type 'ElementClass'. |
| 27 | + |
| 28 | + |
| 29 | +==== tests/cases/compiler/jsxComponentTypeErrors.tsx (7 errors) ==== |
| 30 | + namespace JSX { |
| 31 | + export interface Element { |
| 32 | + type: 'element'; |
| 33 | + } |
| 34 | + export interface ElementClass { |
| 35 | + type: 'element-class'; |
| 36 | + } |
| 37 | + } |
| 38 | + |
| 39 | + function FunctionComponent<T extends string>({type}: {type?: T}) { |
| 40 | + return { |
| 41 | + type |
| 42 | + } |
| 43 | + } |
| 44 | + FunctionComponent.useThis = function() { |
| 45 | + return <this type="foo" />; |
| 46 | + ~~~~ |
| 47 | +!!! error TS2786: 'this' cannot be used as a JSX component. |
| 48 | +!!! error TS2786: Its return type '{ type: "foo" | undefined; }' is not a valid JSX element. |
| 49 | +!!! error TS2786: Types of property 'type' are incompatible. |
| 50 | +!!! error TS2786: Type '"foo" | undefined' is not assignable to type '"element"'. |
| 51 | +!!! error TS2786: Type 'undefined' is not assignable to type '"element"'. |
| 52 | + } |
| 53 | + |
| 54 | + class ClassComponent { |
| 55 | + type = 'string'; |
| 56 | + } |
| 57 | + |
| 58 | + const MixedComponent = Math.random() ? FunctionComponent : ClassComponent; |
| 59 | + |
| 60 | + const elem1 = <FunctionComponent type="abc" />; |
| 61 | + ~~~~~~~~~~~~~~~~~ |
| 62 | +!!! error TS2786: 'FunctionComponent' cannot be used as a JSX component. |
| 63 | +!!! error TS2786: Its return type '{ type: "abc" | undefined; }' is not a valid JSX element. |
| 64 | +!!! error TS2786: Types of property 'type' are incompatible. |
| 65 | +!!! error TS2786: Type '"abc" | undefined' is not assignable to type '"element"'. |
| 66 | +!!! error TS2786: Type 'undefined' is not assignable to type '"element"'. |
| 67 | + const elem2 = <FunctionComponent<"abc"> />; |
| 68 | + ~~~~~~~~~~~~~~~~~ |
| 69 | +!!! error TS2786: 'FunctionComponent' cannot be used as a JSX component. |
| 70 | +!!! error TS2786: Its return type '{ type: "abc" | undefined; }' is not a valid JSX element. |
| 71 | + const elem3 = <ClassComponent />; |
| 72 | + ~~~~~~~~~~~~~~ |
| 73 | +!!! error TS2786: 'ClassComponent' cannot be used as a JSX component. |
| 74 | +!!! error TS2786: Its instance type 'ClassComponent' is not a valid JSX element. |
| 75 | +!!! error TS2786: Types of property 'type' are incompatible. |
| 76 | +!!! error TS2786: Type 'string' is not assignable to type '"element-class"'. |
| 77 | + const elem4 = <MixedComponent />; |
| 78 | + ~~~~~~~~~~~~~~ |
| 79 | +!!! error TS2786: 'MixedComponent' cannot be used as a JSX component. |
| 80 | +!!! error TS2786: Its element type 'ClassComponent | { type: string | undefined; }' is not a valid JSX element. |
| 81 | +!!! error TS2786: Type 'ClassComponent' is not assignable to type 'Element | ElementClass | null'. |
| 82 | +!!! error TS2786: Type 'ClassComponent' is not assignable to type 'ElementClass'. |
| 83 | + |
| 84 | + const obj = { |
| 85 | + MemberFunctionComponent() { |
| 86 | + return {}; |
| 87 | + }, |
| 88 | + MemberClassComponent: class {}, |
| 89 | + }; |
| 90 | + |
| 91 | + const elem5 = <obj.MemberFunctionComponent />; |
| 92 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 93 | +!!! error TS2786: 'obj.MemberFunctionComponent' cannot be used as a JSX component. |
| 94 | +!!! error TS2786: Its return type '{}' is not a valid JSX element. |
| 95 | +!!! error TS2786: Property 'type' is missing in type '{}' but required in type 'Element'. |
| 96 | +!!! related TS2728 tests/cases/compiler/jsxComponentTypeErrors.tsx:3:5: 'type' is declared here. |
| 97 | + const elem6 = <obj. MemberClassComponent />; |
| 98 | + ~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 99 | +!!! error TS2786: 'obj. MemberClassComponent' cannot be used as a JSX component. |
| 100 | +!!! error TS2786: Its instance type 'MemberClassComponent' is not a valid JSX element. |
| 101 | +!!! error TS2786: Property 'type' is missing in type 'MemberClassComponent' but required in type 'ElementClass'. |
| 102 | +!!! related TS2728 tests/cases/compiler/jsxComponentTypeErrors.tsx:6:5: 'type' is declared here. |
| 103 | + |
0 commit comments