dotansimha / dotansimha/graphql-code-generator

`Exact` type doesn't protect against errors

Open
#7,684 7 comments 1 reaction 1 assignee Claimed by @charlypoly View on GitHub
core stage/1-reproduction
Dominant language
TypeScript
Stars
11.3k
Forks
1.4k
Avg merge
1d 1h
Merged PRs (30d)
23

Description

After this issue https://github.com/dotansimha/graphql-code-generator/issues/4120 in generated files appears `Exact` type
```
type Exact = {
[K in keyof T]: T[K];
};
```
that doesn't do anything

Example 1:
```
type Variables = { [key: string]: never }

declare const query: (variables: QueryVariables) => void

query({}) // Ok
query({a: 1}) // Argument of type '{ a: number; }' is not assignable to parameter of type 'Variables'
```
vs `Exact` version
```
type Variables = { [key: string]: never }

declare const query: (variables: Exact) => void

query({}) // Ok
query({a: 1}) // Argument of type '{ a: number; }' is not assignable to parameter of type 'Variables'
```
**It works absolutely the same**

Example 2:
```
type Variables = { email: string }

declare const query: (variables: Variables) => void

query({email: 'email', password: 'password'}) // Argument of type '{ email: string; password: string; }' is not assignable to parameter of type 'Variables'.

const variables = {email: 'email', password: 'password'}
query(variables ) // Ok
```
I can pass additional fields and have no errors in TS, but have errors in runtime
vs `Exact` version
```
type Variables = { email: string }

declare const query: (variables: Exact) => void

query({email: 'email', password: 'password'}) // Argument of type '{ email: string; password: string; }' is not assignable to parameter of type 'Variables'.

const variables = {email: 'email', password: 'password'}
query(variables ) // Ok
```
**It works absolutely the same and doesn't protect against errors**

[Link to the TS playground](https://www.typescriptlang.org/play?#code/C4TwDgpgBAogHgQwMbADwBUoTsCA7AEwGcoBvKAbQGsIQAuKI4AJwEs8BzAXQYFc8qeAPYB3PFAC+APigBeMgCgolANJR2UGiCEAzKOh76KKrgG4FE8wtCQoAQTllKWhkzadDeCADcIzSdbg0ABCjqQQALYIrAA2rizsHKYSCgoEEEgxCMzQSEJ4TFAAjrx+IHYMABTe2awIAEYxEEQMdgCUcjLeQqwEaRlZOVB5BcDFpcwg8MjAFVDVtQ1NLbCIKKh2Uh2yXT19-ZnZufmFJWXBVTVsS80Mwdu7vQeDx6PjZdMoF-NXdY23qxmqGCW06UG6TwUI0KvxuRAc8nICAYAEYAgozpM7JVSBIOgB6fFQADyVAxE3KC2u-3hBKJpNSmKma1mOLxUEJUAA6kJmFQSMAABbQIgICIQckfFnY2E09ocok8vkC4WMMUSqEnMay5ahRFYKKxBgAcki0RixoANFAwAgiEQRLyCCbbfbHcwCMb0UzgjizUaoKbDRbra6HU6XXbwx7jezOQyfVS-rq6VAAMIIcRhqAIAgEVjAVj5BAxKA6VgQGLERkUz7AX3hYMm-0hm1R93OwNhjux1NK-lQIUi9WSyZ13065r3BXc3kDodq8XWzMEKAEITNPDGsZgZhCXAoMt7iLqYBAA)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.