Relay-compiler-language-typescript: Not compatible with @types/relay-runtime 1.3.9

Created on 4 Feb 2019  路  10Comments  路  Source: relay-tools/relay-compiler-language-typescript

I don't know whether it's broken because of @types/relay-runtime 1.3.9 (1.3.8 works) or generated types are obsolete.

generated/AppQuery.graphql.ts:96:7 - error TS2739: Type '{ "kind": string; "fragment": { "kind": string; "name": string; "type": string; "metadata": null; "argumentDefinitions": { "kind": string; "name": string; "type": string; "defaultValue": null; }[]; "selections": ({ "kind": string; ... 4 more ...; "selections"?: undefined; } | { ...; } | { ...; })[]; }; "operation": ...' is missing the following properties from type 'ConcreteRequest': operationKind, name, id, text, metadata

96 const node: ConcreteRequest = (function(){
         ~~~~

generated/CreateWebMutation.graphql.ts:43:7 - error TS2739: Type '{ "kind": string; "fragment": { "kind": string; "name": string; "type": string; "metadata": null; "argumentDefinitions": { "kind": string; "name": string; "type": string; "defaultValue": null; }[]; "selections": { "kind": string; "alias": null; ... 5 more ...; "selections": { ...; }[]; }[]; }; "operation": { ...; };...' is missing the following properties from type 'ConcreteRequest': operationKind, name, id, text, metadata

43 const node: ConcreteRequest = (function(){
         ~~~~

generated/DeleteWebMutation.graphql.ts:36:7 - error TS2739: Type '{ "kind": string; "fragment": { "kind": string; "name": string; "type": string; "metadata": null; "argumentDefinitions": { "kind": string; "name": string; "type": string; "defaultValue": null; }[]; "selections": { "kind": string; "alias": null; ... 5 more ...; "selections": { ...; }[]; }[]; }; "operation": { ...; };...' is missing the following properties from type 'ConcreteRequest': operationKind, name, id, text, metadata

36 const node: ConcreteRequest = (function(){
         ~~~~

generated/SetUserThemeMutation.graphql.ts:37:7 - error TS2739: Type '{ "kind": string; "fragment": { "kind": string; "name": string; "type": string; "metadata": null; "argumentDefinitions": { "kind": string; "name": string; "type": string;"defaultValue": null; }[]; "selections": { "kind": string; "alias": null; ... 5 more ...; "selections": { ...; }[]; }[]; }; "operation": { ...; };...' is missing the following properties from type 'ConcreteRequest': operationKind, name, id, text, metadata

37 const node: ConcreteRequest = (function(){
         ~~~~

generated/signinMutation.graphql.ts:44:7 - error TS2739: Type '{ "kind": string; "fragment": { "kind": string; "name": string; "type": string; "metadata": null; "argumentDefinitions": { "kind": string; "name": string; "type": string; "defaultValue": null; }[]; "selections": { "kind": string; "alias": null; ... 5 more ...; "selections": ({ ...; } | { ...; })[]; }[]; }; "operatio...' is missing the following properties from type 'ConcreteRequest': operationKind, name, id, text, metadata

44 const node: ConcreteRequest = (function(){
         ~~~~

generated/webMutation.graphql.ts:46:7 - error TS2739: Type '{ "kind": string; "fragment": { "kind": string; "name": string; "type": string; "metadata": null; "argumentDefinitions": { "kind": string; "name": string; "type": string; "defaultValue": null; }[]; "selections": { "kind": string; "alias": null; ... 5 more ...; "selections": { ...; }[]; }[]; }; "operation": { ...; };...' is missing the following properties from type 'ConcreteRequest': operationKind, name, id, text, metadata

46 const node: ConcreteRequest = (function(){
         ~~~~

pages/_app.tsx:67:49 - error TS2339: Property 'text' does not exist on type 'RequestNode'.
  Property 'text' does not exist on type 'ConcreteBatchRequest'.

67         body: JSON.stringify({ query: operation.text, variables }),

Related https://github.com/este/este/issues/1642

help wanted

Most helpful comment

@steida Solution coming as relaxed typings v1.3.12
https://www.npmjs.com/package/@types/relay-runtime

Thanks @mattkrick @alloy @sibelius

All 10 comments

you know, that's probably my bad, i made the typedef more strict to add support for getRequest.
relay v1.7.0 changed the defs a little bit, & now relay v2.0.0 has completely revamped the shape of some of these interfaces:

unless you're calling getRequest in your app, none of this really matters.

the right thing to do would be to release new typedefs for v.1.7.0 and another one for v2.0.0 (and my gut tells me that as @match matures, we'll need new defs for the next version, too)

the fast thing to do would be to excluded generated files from type checking, which should speed up build times, too

Sure I can, but that's why I generate types. To use them.

ConcreteRequest will change very often, maybe it could be any or unknow, so it will break less

@mattkrick @alloy @sibelius Same for me. With @types/relay-runtime v1.3.8 works because of ConcreteRequest = any while with v1.3.10 breaks. I think that it is a problem with the typings because by semver, it is a breaking change ... not just a patch.
Could be possible to fix this issue:

  • relax the types for ConcreteRequest in the typings
  • fix this package to output compatible with v1.3.10
    ?

we can relax ConcreteRequest types as they will keep changing and relay adds more transforms like @defer, @stream and so on

DT typings have no notion of semver.

I currently do not have any spare time to spend on this, so I'd love somebody else to PR a solution. I agree with @mattkrick that it is likely we'll need separate types for <2 and >=2, but that might be a bit much to tackle now, so for expediency sake perhaps most of those changes should be reverted for now?

@mattkrick is the "solution" to rollback this commit on typings?

https://github.com/DefinitelyTyped/DefinitelyTyped/commit/f044c380f6be2c942201f6207c11461a946e1856#diff-03ed2ffcefe6022264efc0c0849fee14

I do believe that the compiler is a bit far from these typings.

yeah, reverting for v1.3 is best. try keeping getRequest and just set it to any though.

I started v2 here: https://github.com/mattkrick/DefinitelyTyped/blob/v2.0/types/relay-runtime/index.d.ts
So much changed that I just started fresh. I ran flow-to-typescript over the whole thing & then made fixes where the conversion failed. still about 1 hour left to spend on it if anyone is itching to get it published feel free! (also i'm the worst with export syntax, feel free to let me know if there's a cleaner way!)

@steida Solution coming as relaxed typings v1.3.12
https://www.npmjs.com/package/@types/relay-runtime

Thanks @mattkrick @alloy @sibelius

Ok, closing this one. Looking forward to the typings for v2 and I expect to be able to pitch in on those again in another few weeks.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

steida picture steida  路  6Comments

wongmjane picture wongmjane  路  7Comments

RichardLindhout picture RichardLindhout  路  17Comments

janicduplessis picture janicduplessis  路  3Comments

sgwilym picture sgwilym  路  7Comments