question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Typescript template immutable types, missing readonly attribute on __typename

See original GitHub issue

When I use CODEGEN_IMMUTABLE_TYPES=true I get this output:

  export type Query = {
    __typename?: "Query";
    readonly tenants: ReadonlyArray<Tenants>;
    readonly plugins: ReadonlyArray<Plugins>;
  };

I guess the __typename property should also have a readonly attribute in this case?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:12 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
jonaskellocommented, May 23, 2018

I had not upgraded the graphql-codegen-typescript-template package to 0.9.1. After I did that it works! 👍

0reactions
dotansimhacommented, Aug 31, 2019

What do you mean by “more static”? it’s static in the generated type, and static in the resolvers signature (if you are using typescript-resolvers), so if you change the GraphQL type - it will change the generated file, and then the build will fail because of an invalid return value from the resolvers. Am I missing something? What is the benefit of generating the typename in a different variable?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Real Immutable Types With TypeScript - Temple Coding
When writing TypeScript there's a pretty easy, simple solution to create immutable objects and it doesn't involve adding third-party libraries.
Read more >
Immutable TypeScript - Paul-Sebastian Codes
TypeScript has this syntax where you can tell the compiler that an object is of a specific type after declaring it. It's called...
Read more >
Google TypeScript Style Guide
Use readonly​​ Mark properties that are never reassigned outside of the constructor with the readonly modifier (these need not be deeply immutable).
Read more >
Argument of type 'readonly ...' is not assignable to parameter ...
By setting the parameter as readonly, typescript won't complain anymore ... This way, you're not passing the original, immutable array, ...
Read more >
Documentation - TypeScript 3.4
TypeScript 3.4 can now produce generic function types when inference from other generic functions produces free type variables for inferences. This means many ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found