-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Repeated mapped type inference causes incorrect typeToString results #23897
Comments
Better repro from #25295
|
@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? |
This is a pretty big deal breaker for my validator library 😢 https://github.com/Jomik/cerberus |
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 |
Ellipsis isn't great, in my opinion, unless some kind of "truncate" flag was enabled or something. Displaying the detected recursive type (without expansion) would be much better than I think TS already does this, type Recursive<T> = { r: T | Recursive<T> };
//Recursive<number>
declare const r: Recursive<number>;
type A = number;
//number
declare const a: A; 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. declare function schema<T> (value : T) : (
{
field : T
}
);
//Should be { field : { field : boolean } }
//But is { field : any }
const x = schema(schema(true));
//No matter how many times I call schema<>(),
//It should show the full type
//because it isn't an infinitely recursive type.
//In this case, it's just 4 levels deep
const y = schema(schema(schema(schema(true)))); Edit: Looks like my issue is related to this one, #26228 As for ellipsis not being great (in my opinion), #26238 |
Same here. Here's some code to give a rough idea of what I have going on (not tested): import { User } from 'oidc-client';
import { combineReducers } from 'redux';
import { Action, handleActions } from 'redux-actions';
const enum AuthActionType {
Callback = 'AUTH_CALLBACK',
}
const userReducer = handleActions(
{
[AuthActionType.Callback]: (state: State, action: Action<User>) => >action.payload,
},
null
);
const authReducer = combineReducers({
user: userReducer,
});
const rootReducer = combineReducers({
auth: authReducer,
});
type State = ReturnType<typeof rootReducer>; At this point type State = {
auth: {
user: any
}
} |
I'm not sure if I've mentioned this before but I'll just add this again. This isn't just a type display issue. It's also a declaration emit issue. The display will show [EDIT] |
@weswigham Sure you don't want to leave this open? As it seems like the issue still exists after the PR. |
Oooo GitHub not picking up on the word "doesn't" before "fix". 🌞 |
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
Expected behavior:
FinalType
's hover type should be{ test: { test_inner: string } }
Actual behavior: Shows as
{ test: { test_inner: any } }
Playground Link: Link
The text was updated successfully, but these errors were encountered: