Skip to content

Commit 0f0a8a1

Browse files
committed
Add regression tests
1 parent 2632ac2 commit 0f0a8a1

File tree

3 files changed

+153
-0
lines changed

3 files changed

+153
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
tests/cases/compiler/recursiveTypeRelations.ts(8,5): error TS2391: Function implementation is missing or not immediately following the declaration.
2+
tests/cases/compiler/recursiveTypeRelations.ts(27,38): error TS2304: Cannot find name 'ClassNameObject'.
3+
tests/cases/compiler/recursiveTypeRelations.ts(27,61): error TS2304: Cannot find name 'ClassNameObject'.
4+
5+
6+
==== tests/cases/compiler/recursiveTypeRelations.ts (3 errors) ====
7+
// Repro from #14896
8+
9+
type Attributes<Keys extends string> = {
10+
[Key in Keys]: string;
11+
}
12+
13+
class Query<A extends Attributes<keyof A>> {
14+
multiply<B extends Attributes<keyof B>>(x: B): Query<A & B>;
15+
~~~~~~~~
16+
!!! error TS2391: Function implementation is missing or not immediately following the declaration.
17+
}
18+
19+
// Repro from #14940
20+
21+
type ClassName<S> = keyof S;
22+
type ClassNameMap<S> = { [K in keyof S]?: boolean }
23+
type ClassNameObjectMap<S> = object & ClassNameMap<S>;
24+
type ClassNameArg<S> = ClassName<S> | ClassNameObjectMap<S>;
25+
26+
export function css<S extends { [K in keyof S]: string }>(styles: S, ...classNames: ClassNameArg<S>[]): string {
27+
const args = classNames.map(arg => {
28+
if (arg == null) {
29+
return null;
30+
}
31+
if (typeof arg == "string") {
32+
return styles[arg];
33+
}
34+
if (typeof arg == "object") {
35+
return Object.keys(arg).reduce<ClassNameObject>((obj: ClassNameObject, key: keyof S) => {
36+
~~~~~~~~~~~~~~~
37+
!!! error TS2304: Cannot find name 'ClassNameObject'.
38+
~~~~~~~~~~~~~~~
39+
!!! error TS2304: Cannot find name 'ClassNameObject'.
40+
const exportedClassName = styles[key];
41+
obj[exportedClassName] = (arg as ClassNameMap<S>)[key];
42+
return obj;
43+
}, {});
44+
}
45+
});
46+
return "";
47+
}
48+
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
//// [recursiveTypeRelations.ts]
2+
// Repro from #14896
3+
4+
type Attributes<Keys extends string> = {
5+
[Key in Keys]: string;
6+
}
7+
8+
class Query<A extends Attributes<keyof A>> {
9+
multiply<B extends Attributes<keyof B>>(x: B): Query<A & B>;
10+
}
11+
12+
// Repro from #14940
13+
14+
type ClassName<S> = keyof S;
15+
type ClassNameMap<S> = { [K in keyof S]?: boolean }
16+
type ClassNameObjectMap<S> = object & ClassNameMap<S>;
17+
type ClassNameArg<S> = ClassName<S> | ClassNameObjectMap<S>;
18+
19+
export function css<S extends { [K in keyof S]: string }>(styles: S, ...classNames: ClassNameArg<S>[]): string {
20+
const args = classNames.map(arg => {
21+
if (arg == null) {
22+
return null;
23+
}
24+
if (typeof arg == "string") {
25+
return styles[arg];
26+
}
27+
if (typeof arg == "object") {
28+
return Object.keys(arg).reduce<ClassNameObject>((obj: ClassNameObject, key: keyof S) => {
29+
const exportedClassName = styles[key];
30+
obj[exportedClassName] = (arg as ClassNameMap<S>)[key];
31+
return obj;
32+
}, {});
33+
}
34+
});
35+
return "";
36+
}
37+
38+
39+
//// [recursiveTypeRelations.js]
40+
// Repro from #14896
41+
"use strict";
42+
exports.__esModule = true;
43+
var Query = (function () {
44+
function Query() {
45+
}
46+
return Query;
47+
}());
48+
function css(styles) {
49+
var classNames = [];
50+
for (var _i = 1; _i < arguments.length; _i++) {
51+
classNames[_i - 1] = arguments[_i];
52+
}
53+
var args = classNames.map(function (arg) {
54+
if (arg == null) {
55+
return null;
56+
}
57+
if (typeof arg == "string") {
58+
return styles[arg];
59+
}
60+
if (typeof arg == "object") {
61+
return Object.keys(arg).reduce(function (obj, key) {
62+
var exportedClassName = styles[key];
63+
obj[exportedClassName] = arg[key];
64+
return obj;
65+
}, {});
66+
}
67+
});
68+
return "";
69+
}
70+
exports.css = css;
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Repro from #14896
2+
3+
type Attributes<Keys extends string> = {
4+
[Key in Keys]: string;
5+
}
6+
7+
class Query<A extends Attributes<keyof A>> {
8+
multiply<B extends Attributes<keyof B>>(x: B): Query<A & B>;
9+
}
10+
11+
// Repro from #14940
12+
13+
type ClassName<S> = keyof S;
14+
type ClassNameMap<S> = { [K in keyof S]?: boolean }
15+
type ClassNameObjectMap<S> = object & ClassNameMap<S>;
16+
type ClassNameArg<S> = ClassName<S> | ClassNameObjectMap<S>;
17+
18+
export function css<S extends { [K in keyof S]: string }>(styles: S, ...classNames: ClassNameArg<S>[]): string {
19+
const args = classNames.map(arg => {
20+
if (arg == null) {
21+
return null;
22+
}
23+
if (typeof arg == "string") {
24+
return styles[arg];
25+
}
26+
if (typeof arg == "object") {
27+
return Object.keys(arg).reduce<ClassNameObject>((obj: ClassNameObject, key: keyof S) => {
28+
const exportedClassName = styles[key];
29+
obj[exportedClassName] = (arg as ClassNameMap<S>)[key];
30+
return obj;
31+
}, {});
32+
}
33+
});
34+
return "";
35+
}

0 commit comments

Comments
 (0)