Repeated mapped type inference causes incorrect typeToString results #23897
Copy link
Copy link
Closed as not planned
Closed as not planned
Copy link
Labels
7.0 LS MigrationBugA bug in TypeScriptA bug in TypeScriptDomain: LS: Type DisplayBugs relating to showing types in Quick Info/Tooltips, Signature Help, or Completion InfoBugs relating to showing types in Quick Info/Tooltips, Signature Help, or Completion Info
Milestone
Description
TypeScript Version: 2.8.0-insiders.20180320
Search Terms: mapped type inference display typetostring
Code
Via https://stackoverflow.com/questions/50181650/type-inference-lost-inner-level-types-in-typescript
interface IAction {
type: string;
}
type Reducer<S> = (state: S, action: IAction) => S
function combineReducers<S>(reducers: { [K in keyof S]: Reducer<S[K]> }): Reducer<S> {
const dummy = {} as S;
return () => dummy;
}
const test_inner = (test: string, action: IAction) => {
return 'dummy';
}
const test = combineReducers({
test_inner
});
const test_outer = combineReducers({
test
});
// '{test: { test_inner: any } }'
type FinalType = ReturnType<typeof test_outer>;
var k: FinalType;
k.test.test_inner // 'string'Expected behavior: FinalType's hover type should be { test: { test_inner: string } }
Actual behavior: Shows as { test: { test_inner: any } }
Playground Link: Link
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
7.0 LS MigrationBugA bug in TypeScriptA bug in TypeScriptDomain: LS: Type DisplayBugs relating to showing types in Quick Info/Tooltips, Signature Help, or Completion InfoBugs relating to showing types in Quick Info/Tooltips, Signature Help, or Completion Info
Activity
RyanCavanaugh commentedon Jun 28, 2018
Better repro from #25295
weswigham commentedon Jun 28, 2018
Nathan Shively-Sanders (@sandersn) didn't we explcitly limit reverse mapped type output to one level deep for lack of a better method of stopping infinite recursion? Is this potentially related?
Jomik commentedon Jun 29, 2018
This is a pretty big deal breaker for my validator library 😢 https://github.com/Jomik/cerberus
Is it not possible to either display more layers, 9 or so. Or detect recursion and display that rather than "any"?
osdiab commentedon Jul 22, 2018
In my case of a recursive type exhibiting this error (#25860), sounds like displaying it with some kind of ellipsis or placeholder type would be nicer than just dropping down to
any—that's a misleading type, given that it actually removes information from the display of the type. Not sure what concerns there would be though since I don't know how these serialized types ultimately get used, but in the case of VSCode type display the current behavior isn't great.AnyhowStep commentedon Aug 21, 2018
Ellipsis isn't great, in my opinion, unless some kind of "truncate" flag was enabled or something.
Having the type hidden in ellipsis slows down a developer when they have to figure out what's in the ellipsis. (TS 3.0 seems to do that for types that are too long at the moment and it slows me down quite a bit when having to figure out what's truncated)
Displaying the detected recursive type (without expansion) would be much better than
anyor..., for generic types that have not had concrete types substituted in the parameters.I think TS already does this,
However, if it can somehow deduce that there's no infinite recursion, or that it stops at a reasonable depth, when a concrete type has been substituted in, it should just display the full type.
Edit: Looks like my issue is related to this one, #26228
As for ellipsis not being great (in my opinion), #26238
KaelWD commentedon Sep 1, 2018
I seem to be getting the opposite of this. VSCode shows what I expect the type to be, but tsc thinks it's



neverI'll try to get a simple repro together,
VExpansionPanelContentInstanceis a Vue component with some circular references.codeaid commentedon Sep 28, 2018
Same here. Here's some code to give a rough idea of what I have going on (not tested):
At this point
Stateis showing as3 remaining items
weswigham commentedon Nov 13, 2018
Oooo GitHub not picking up on the word "doesn't" before "fix". 🌞
RyanCavanaugh commentedon Dec 3, 2025
Closing language service bugs related to the 6.0 implementation. For more information, see #62827