apollographql / apollographql/apollo-tooling

[apollo-codegen-typescript] interfaces should perhaps be alias types

Open
#2,016 0 comments 5 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
3k
Forks
460
PR merge metrics
No merged PRs in 30d

Description

Hey,

I think apollo-codegen-typescript interface should be alias types instead. I'll explain why:
- interfaces are a contract you are willing to implement, types are a representation of your data (I think apollo generates type for the second case)
- types are more flexible than interface, e.g. interfaces do not have index signatures

In the large project I'm working on, we used to create generics for components such as ``, but we are refactoring the generics to be ``, which is more precise and useful.

Doing so results in a bug when used with apollo types:
` />`
Type 'MyDataType' is not assignable to type 'Record'.
Index signature is missing in type 'MyDataType'

I already tried modifying [this file](https://github.com/apollographql/apollo-tooling/blob/master/packages/apollo-codegen-typescript/src/codeGeneration.ts) to use `this.typeAliasGenericUnion` instead of this.interface, but without much luck (I got lost in the code).

What do you think about it? I think this would be quite easy to change, and would gladly do so if given a bit of help.

Have a nice day!

Contributor guide

Open the contributing guide

Research direction

Read packages/apollo-codegen-typescript/src/codeGeneration.ts and trace how this.interface and typeAliasGenericUnion are selected. Reproduce the reported Record generic incompatibility, then verify that generated Apollo TypeScript models use the intended alias form without losing the existing generated structure.

Written by the indexing model from the issue text.

Assessment

Tech stack
graphql, typescript
Domain
tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.