Vue-apollo: TypeError in types/options.d.ts

Created on 5 Jun 2018  路  4Comments  路  Source: vuejs/vue-apollo

I'm getting an Error at Version 3.0.0-beta.16

Type 'keyof T' does not satisfy the constraint 'string'.
  Type 'string | number | symbol' is not assignable to type 'string'.
    Type 'number' is not assignable to type 'string'.
    4 | // include Omit type from https://github.com/Microsoft/TypeScript/issues/12215
    5 | type Diff<T extends string, U extends string> = ({ [P in T]: P } & { [P in U]: never } & { [x: string]: never })[T];
  > 6 | type Omit<T, K extends keyof T> = { [P in Diff<keyof T, K>]?: T[P] };
      |                                                ^
    7 |
    8 | type ApolloVueThisType<V> = V & { [key: string]: any };
    9 | type VariableFn<V> = ((this: ApolloVueThisType<V>) => Object) | Object;

Most helpful comment

If I change options.d.ts from

type Diff<T extends string, U extends string> = ({ [P in T]: P } & { [P in U]: never } & { [x: string]: never })[T];
type Omit<T, K extends keyof T> = { [P in Diff<keyof T, K>]?: T[P] };

to

type Diff<T extends string, U extends string> = ({ [P in T]: P } & { [P in U]: never } & { [x: string]: never })[T];
type Omit<T, K extends keyof T> = { [P in Diff<Extract<keyof T, string>, Extract<K, string>>]?: T[P] };

or

type Property = string | number | symbol;
type Diff<T extends Property, U extends Property> = ({ [P in T]: P } & { [P in U]: never } & { [x: string]: never })[T];
type Omit<T, K extends keyof T> = { [P in Diff<keyof T, K>]?: T[P] };

then the build passes.

I'll put in a PR; most likely it will be the latter change.

All 4 comments

I've had to revert back to version 3.0.0-alpha.2 to get things to build again, but that's basically because 3.0.0-alpha.3 introduced TypeScript definitions to this library. I'm not sure why it's failing only now, because I had built my app with 3.0.0-beta.5 about two weeks ago and it was working; now it's breaking even when I revert back to 3.0.0-beta.5. This smells like some dependency of vue-apollo recently got updated that caused things to break.

I think I see what's new... TypeScript 2.9 recently came out, and has breaking changes:

https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes#keyof-now-includes-string-number-and-symbol-keys

If I change options.d.ts from

type Diff<T extends string, U extends string> = ({ [P in T]: P } & { [P in U]: never } & { [x: string]: never })[T];
type Omit<T, K extends keyof T> = { [P in Diff<keyof T, K>]?: T[P] };

to

type Diff<T extends string, U extends string> = ({ [P in T]: P } & { [P in U]: never } & { [x: string]: never })[T];
type Omit<T, K extends keyof T> = { [P in Diff<Extract<keyof T, string>, Extract<K, string>>]?: T[P] };

or

type Property = string | number | symbol;
type Diff<T extends Property, U extends Property> = ({ [P in T]: P } & { [P in U]: never } & { [x: string]: never })[T];
type Omit<T, K extends keyof T> = { [P in Diff<keyof T, K>]?: T[P] };

then the build passes.

I'll put in a PR; most likely it will be the latter change.

Nice 馃憤

Was this page helpful?
0 / 5 - 0 ratings

Related issues

igaloly picture igaloly  路  3Comments

ais-one picture ais-one  路  4Comments

wangxiangyao picture wangxiangyao  路  4Comments

AruXc picture AruXc  路  4Comments

danthareja picture danthareja  路  4Comments