Repository navigation
Closed
Labels
Needs More InfoThe issue still hasn't been fully clarifiedThe issue still hasn't been fully clarified
Description
TypeScript Version: 3.6.2
Search Terms:
type instantiation to deepl
Code
type Func<P extends any[], R> = (...args: P) => R;
type AnyFunc = Func<any, any>;
type IsType<M, T, Z, L> = T extends M ? Z : L;
type IsScalar<T, Z, L> = IsType<string | boolean | number, T, Z, L>;
type WithTypeNameValue<T> = T & {
__typename?: true;
};
type AliasType<T> = WithTypeNameValue<T> & {
__alias?: Record<string, WithTypeNameValue<T>>;
};
export type AliasedReturnType<T> = {
[P in keyof T]: T[P];
} &
Record<
string,
{
[P in keyof T]: T[P];
}
>;
type ArgsType<F extends AnyFunc> = F extends Func<infer P, any> ? P : never;
type OfType<T> = T extends Array<infer R> ? R : T;
type FirstArgument<F extends AnyFunc> = OfType<ArgsType<F>>;
interface GraphQLResponse {
data?: Record<string, any>;
errors?: Array<{
message: string;
}>;
}
export type State<T> = {
[P in keyof T]?: T[P] extends (Array<infer R> | undefined)
? Array<AliasedReturnType<State<R>>>
: T[P] extends AnyFunc
? AliasedReturnType<State<ReturnType<T[P]>>>
: IsScalar<T[P], T[P], AliasedReturnType<State<T[P]>>>;
};
export type PlainObject<T> = {
[P in keyof T]?: T[P] extends (Array<infer R> | undefined)
? Array<PlainObject<R>>
: T[P] extends AnyFunc
? PlainObject<ReturnType<T[P]>>
: IsScalar<T[P], T[P], PlainObject<T[P]>>;
};
type ResolveValue<T> = T extends Array<infer R>
? SelectionSet<R>
: T extends AnyFunc
? IsScalar<
ReturnType<T>,
[FirstArgument<T>],
[FirstArgument<T>, SelectionSet<OfType<ReturnType<T>>>]
>
: IsScalar<T, T extends undefined ? undefined : true, SelectionSet<T>>;
export type SelectionSet<T> = IsScalar<
T, T extends undefined ? undefined : true
, AliasType<
{
[P in keyof T]?: ResolveValue<T[P]>;
}
>>;
type GraphQLReturner<T> = T extends Array<infer R> ? SelectionSet<R> : SelectionSet<T>;
type OperationToGraphQL<V,T> = (o: GraphQLReturner<V>) => Promise<AliasedReturnType<State<T>>>;
type ResolveApiField<T> = T extends Array<infer R>
? IsScalar<R, R, State<R>>
: T extends AnyFunc
? IsScalar<OfType<ReturnType<T>>, T, State<OfType<ReturnType<T>>>>
: IsScalar<T, T, State<T>>;
type ApiFieldToGraphQL<V,T> = (o: ResolveValue<V>) => Promise<ResolveApiField<T>>;
type fetchOptions = ArgsType<typeof fetch>;
export type PageInfo = {
__typename?: "PageInfo",
last?:string,
limit?:number,
next?:boolean
}
export type Project = {
sources:(props:{ last?:string, limit?:number}) => FakerSourceConnection,
}
export type FakerSourceConnection = {
__typename?: "FakerSourceConnection",
pageInfo:PageInfo,
sources?:FakerSource[]
}
export type FakerSource = {
__typename?: "FakerSource",
checksum?:string,
contents?:string,
filename?:string,
getUrl?:string
}
const project:State<Project>
const project: AliasedReturnType<State<Project>>
project.sources!.sources!.length > 0Last line breaks
Expected behavior:
Nothing happens in ts <3.6
Actual behavior:
getting error:
Type instantiation is excessively deep and possibly infinite.
Moreover I am getting this error in VSCode. I know this is a design-limitation and understood it already. However it works for me with previous versions of TS which had that limitation implemented before 3.5.
Here is a link to my library for you to better understand whats going on.
https://github.com/graphql-editor/graphql-zeus
Playground Link:
3.6 not available in playground
Reacted by Matthew Dordal
Reacted by AnyhowStep
Metadata
Metadata
Assignees
Labels
Needs More InfoThe issue still hasn't been fully clarifiedThe issue still hasn't been fully clarified
Activity
aexol commentedon Sep 13, 2019
It might be vscode bug because after I put
.sign after the property it starts working. Nevertheless, it is VSCode bug/typescript bug it ruins Developer Experience.AnyhowStep commentedon Sep 13, 2019
Related,
#32079
RyanCavanaugh commentedon Sep 16, 2019
Artur Czemiel (@aexol) changes in type system behavior do occur from version to version. If you can reduce this example to something much smaller we might be able to advise on the specific root cause if needed, otherwise there's not much we can do. Thanks!
aexol commentedon Sep 17, 2019
Ryan Cavanaugh (@RyanCavanaugh) ok I'll try to reduce the minimal example