1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
|
tests/cases/conformance/types/typeRelationships/recursiveTypes/recursiveTypeReferences1.ts(45,7): error TS2322: Type 'number' is not assignable to type 'Box2'.
tests/cases/conformance/types/typeRelationships/recursiveTypes/recursiveTypeReferences1.ts(60,7): error TS2322: Type 'number' is not assignable to type 'string | RecArray<string>'.
tests/cases/conformance/types/typeRelationships/recursiveTypes/recursiveTypeReferences1.ts(66,8): error TS2322: Type 'number' is not assignable to type 'string | string[]'.
tests/cases/conformance/types/typeRelationships/recursiveTypes/recursiveTypeReferences1.ts(72,8): error TS2322: Type 'number' is not assignable to type 'string | (string | string[])[]'.
tests/cases/conformance/types/typeRelationships/recursiveTypes/recursiveTypeReferences1.ts(102,10): error TS2304: Cannot find name 'html'.
tests/cases/conformance/types/typeRelationships/recursiveTypes/recursiveTypeReferences1.ts(104,12): error TS2304: Cannot find name 'html'.
tests/cases/conformance/types/typeRelationships/recursiveTypes/recursiveTypeReferences1.ts(105,7): error TS2304: Cannot find name 'html'.
tests/cases/conformance/types/typeRelationships/recursiveTypes/recursiveTypeReferences1.ts(106,52): error TS2304: Cannot find name 'frag'.
tests/cases/conformance/types/typeRelationships/recursiveTypes/recursiveTypeReferences1.ts(116,11): error TS2304: Cannot find name 'concat'.
tests/cases/conformance/types/typeRelationships/recursiveTypes/recursiveTypeReferences1.ts(116,24): error TS2304: Cannot find name 'concat'.
tests/cases/conformance/types/typeRelationships/recursiveTypes/recursiveTypeReferences1.ts(117,11): error TS2304: Cannot find name 'concat'.
tests/cases/conformance/types/typeRelationships/recursiveTypes/recursiveTypeReferences1.ts(122,11): error TS2304: Cannot find name 'concat'.
tests/cases/conformance/types/typeRelationships/recursiveTypes/recursiveTypeReferences1.ts(127,3): error TS2304: Cannot find name 'assert'.
==== tests/cases/conformance/types/typeRelationships/recursiveTypes/recursiveTypeReferences1.ts (13 errors) ====
type ValueOrArray<T> = T | Array<ValueOrArray<T>>;
const a0: ValueOrArray<number> = 1;
const a1: ValueOrArray<number> = [1, [2, 3], [4, [5, [6, 7]]]];
type HypertextNode = string | [string, { [key: string]: unknown }, ...HypertextNode[]];
const hypertextNode: HypertextNode =
["div", { id: "parent" },
["div", { id: "first-child" }, "I'm the first child"],
["div", { id: "second-child" }, "I'm the second child"]
];
type Json = string | number | boolean | null | Json[] | { [key: string]: Json };
let data: Json = {
caption: "Test",
location: { x: 10, y: 20 },
values: [true, [10, 20], null]
};
interface Box<T> { value: T };
type T1 = Box<T1>;
type T2 = Box<Box<T2>>;
type T3 = Box<Box<Box<T3>>>;
function f1(t1: T1, t2: T2, t3: T3) {
t1 = t2;
t1 = t3;
t2 = t1;
t2 = t3;
t3 = t1;
t3 = t2;
}
type Box1 = Box<Box1> | number;
const b10: Box1 = 42;
const b11: Box1 = { value: 42 };
const b12: Box1 = { value: { value: { value: 42 }}};
type Box2 = Box<Box2 | number>;
const b20: Box2 = 42; // Error
~~~
!!! error TS2322: Type 'number' is not assignable to type 'Box2'.
const b21: Box2 = { value: 42 };
const b22: Box2 = { value: { value: { value: 42 }}};
type RecArray<T> = Array<T | RecArray<T>>;
declare function flat<T>(a: RecArray<T>): Array<T>;
declare function flat1<T>(a: Array<T | Array<T>>): Array<T>
declare function flat2<T>(a: Array<T | Array<T | Array<T>>>): Array<T>;
flat([1, [2, [3]]]); // number[]
flat([[[0]]]); // number[]
flat([[[[[[[[[[[4]]]]]]]]]]]); // number[]
flat([1, 'a', [2]]); // (string | number)[]
flat([1, [2, 'a']]); // (string | number)[]
flat([1, ['a']]); // Error
~
!!! error TS2322: Type 'number' is not assignable to type 'string | RecArray<string>'.
flat1([1, [2, [3]]]); // (number | number[])[]
flat1([[[0]]]); // number[][]
flat1([1, 'a', [2]]); // (string | number)[]
flat1([1, [2, 'a']]); // (string | number)[]
flat1([1, ['a']]); // Error
~
!!! error TS2322: Type 'number' is not assignable to type 'string | string[]'.
flat2([1, [2, [3]]]); // number[]
flat2([[[0]]]); // number[]
flat2([1, 'a', [2]]); // (string | number)[]
flat2([1, [2, 'a']]); // (string | number)[]
flat2([1, ['a']]); // Error
~
!!! error TS2322: Type 'number' is not assignable to type 'string | (string | string[])[]'.
type T10 = T10[];
type T11 = readonly T11[];
type T12 = (T12)[];
type T13 = T13[] | string;
type T14 = T14[] & { x: string };
type T15<X> = X extends string ? T15<X>[] : never;
type ValueOrArray1<T> = T | ValueOrArray1<T>[];
type ValueOrArray2<T> = T | ValueOrArray2<T>[];
declare function foo1<T>(a: ValueOrArray1<T>): T;
declare let ra1: ValueOrArray2<string>;
let x1 = foo1(ra1); // Boom!
type NumberOrArray1<T> = T | ValueOrArray1<T>[];
type NumberOrArray2<T> = T | ValueOrArray2<T>[];
declare function foo2<T>(a: ValueOrArray1<T>): T;
declare let ra2: ValueOrArray2<string>;
let x2 = foo2(ra2); // Boom!
// Repro from #33617 (errors are expected)
type Tree = [HTMLHeadingElement, Tree][];
function parse(node: Tree, index: number[] = []): HTMLUListElement {
return html('ul', node.map(([el, children], i) => {
~~~~
!!! error TS2304: Cannot find name 'html'.
const idx = [...index, i + 1];
return html('li', [
~~~~
!!! error TS2304: Cannot find name 'html'.
html('a', { href: `#${el.id}`, rel: 'noopener', 'data-index': idx.join('.') }, el.textContent!),
~~~~
!!! error TS2304: Cannot find name 'html'.
children.length > 0 ? parse(children, idx) : frag()
~~~~
!!! error TS2304: Cannot find name 'frag'.
]);
}));
}
function cons(hs: HTMLHeadingElement[]): Tree {
return hs
.reduce<HTMLHeadingElement[][]>((hss, h) => {
const hs = hss.pop()!;
return hs.length === 0 || level(h) > level(hs[0])
? concat(hss, [concat(hs, [h])])
~~~~~~
!!! error TS2304: Cannot find name 'concat'.
~~~~~~
!!! error TS2304: Cannot find name 'concat'.
: concat(hss, [hs, [h]]);
~~~~~~
!!! error TS2304: Cannot find name 'concat'.
}, [[]])
.reduce<Tree>((node, hs) =>
hs.length === 0
? node
: concat<Tree[number]>(node, [[hs.shift()!, cons(hs)]])
~~~~~~
!!! error TS2304: Cannot find name 'concat'.
, []);
}
function level(h: HTMLHeadingElement): number {
assert(isFinite(+h.tagName[1]));
~~~~~~
!!! error TS2304: Cannot find name 'assert'.
return +h.tagName[1];
}
|