-
Notifications
You must be signed in to change notification settings - Fork 12.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14991 from Microsoft/fixTypeRelationStackOverflow
Fix type relation stack overflow
- Loading branch information
Showing
13 changed files
with
368 additions
and
262 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 52 additions & 76 deletions
128
tests/baselines/reference/mappedTypeRelationships.errors.txt
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
tests/baselines/reference/recursiveTypeRelations.errors.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
tests/cases/compiler/recursiveTypeRelations.ts(8,5): error TS2391: Function implementation is missing or not immediately following the declaration. | ||
tests/cases/compiler/recursiveTypeRelations.ts(27,38): error TS2304: Cannot find name 'ClassNameObject'. | ||
tests/cases/compiler/recursiveTypeRelations.ts(27,61): error TS2304: Cannot find name 'ClassNameObject'. | ||
|
||
|
||
==== tests/cases/compiler/recursiveTypeRelations.ts (3 errors) ==== | ||
// Repro from #14896 | ||
|
||
type Attributes<Keys extends string> = { | ||
[Key in Keys]: string; | ||
} | ||
|
||
class Query<A extends Attributes<keyof A>> { | ||
multiply<B extends Attributes<keyof B>>(x: B): Query<A & B>; | ||
~~~~~~~~ | ||
!!! error TS2391: Function implementation is missing or not immediately following the declaration. | ||
} | ||
|
||
// Repro from #14940 | ||
|
||
type ClassName<S> = keyof S; | ||
type ClassNameMap<S> = { [K in keyof S]?: boolean } | ||
type ClassNameObjectMap<S> = object & ClassNameMap<S>; | ||
type ClassNameArg<S> = ClassName<S> | ClassNameObjectMap<S>; | ||
|
||
export function css<S extends { [K in keyof S]: string }>(styles: S, ...classNames: ClassNameArg<S>[]): string { | ||
const args = classNames.map(arg => { | ||
if (arg == null) { | ||
return null; | ||
} | ||
if (typeof arg == "string") { | ||
return styles[arg]; | ||
} | ||
if (typeof arg == "object") { | ||
return Object.keys(arg).reduce<ClassNameObject>((obj: ClassNameObject, key: keyof S) => { | ||
~~~~~~~~~~~~~~~ | ||
!!! error TS2304: Cannot find name 'ClassNameObject'. | ||
~~~~~~~~~~~~~~~ | ||
!!! error TS2304: Cannot find name 'ClassNameObject'. | ||
const exportedClassName = styles[key]; | ||
obj[exportedClassName] = (arg as ClassNameMap<S>)[key]; | ||
return obj; | ||
}, {}); | ||
} | ||
}); | ||
return ""; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
//// [recursiveTypeRelations.ts] | ||
// Repro from #14896 | ||
|
||
type Attributes<Keys extends string> = { | ||
[Key in Keys]: string; | ||
} | ||
|
||
class Query<A extends Attributes<keyof A>> { | ||
multiply<B extends Attributes<keyof B>>(x: B): Query<A & B>; | ||
} | ||
|
||
// Repro from #14940 | ||
|
||
type ClassName<S> = keyof S; | ||
type ClassNameMap<S> = { [K in keyof S]?: boolean } | ||
type ClassNameObjectMap<S> = object & ClassNameMap<S>; | ||
type ClassNameArg<S> = ClassName<S> | ClassNameObjectMap<S>; | ||
|
||
export function css<S extends { [K in keyof S]: string }>(styles: S, ...classNames: ClassNameArg<S>[]): string { | ||
const args = classNames.map(arg => { | ||
if (arg == null) { | ||
return null; | ||
} | ||
if (typeof arg == "string") { | ||
return styles[arg]; | ||
} | ||
if (typeof arg == "object") { | ||
return Object.keys(arg).reduce<ClassNameObject>((obj: ClassNameObject, key: keyof S) => { | ||
const exportedClassName = styles[key]; | ||
obj[exportedClassName] = (arg as ClassNameMap<S>)[key]; | ||
return obj; | ||
}, {}); | ||
} | ||
}); | ||
return ""; | ||
} | ||
|
||
|
||
//// [recursiveTypeRelations.js] | ||
"use strict"; | ||
// Repro from #14896 | ||
exports.__esModule = true; | ||
var Query = (function () { | ||
function Query() { | ||
} | ||
return Query; | ||
}()); | ||
function css(styles) { | ||
var classNames = []; | ||
for (var _i = 1; _i < arguments.length; _i++) { | ||
classNames[_i - 1] = arguments[_i]; | ||
} | ||
var args = classNames.map(function (arg) { | ||
if (arg == null) { | ||
return null; | ||
} | ||
if (typeof arg == "string") { | ||
return styles[arg]; | ||
} | ||
if (typeof arg == "object") { | ||
return Object.keys(arg).reduce(function (obj, key) { | ||
var exportedClassName = styles[key]; | ||
obj[exportedClassName] = arg[key]; | ||
return obj; | ||
}, {}); | ||
} | ||
}); | ||
return ""; | ||
} | ||
exports.css = css; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.