Skip to content
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

TypeScript 3.6.3 breaks support for my ts library. Is it backward uncompatible or you corrected something that didn't work before? #33409

Closed
aexol opened this issue Sep 13, 2019 · 4 comments
Assignees
Labels
Needs More Info The issue still hasn't been fully clarified

Comments

@aexol
Copy link

aexol commented Sep 13, 2019

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 > 0

Last 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

@aexol
Copy link
Author

aexol commented 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
Copy link
Contributor

Related,

#32079

@RyanCavanaugh RyanCavanaugh added the Needs More Info The issue still hasn't been fully clarified label Sep 16, 2019
@RyanCavanaugh
Copy link
Member

@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
Copy link
Author

aexol commented Sep 17, 2019

@RyanCavanaugh ok I'll try to reduce the minimal example

@aexol aexol closed this as completed Nov 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs More Info The issue still hasn't been fully clarified
Projects
None yet
Development

No branches or pull requests

3 participants