Use `unknown` as the default any type rather than literal `{}`
See original GitHub issueContext
Referencing the following code:
Currently, with a custom scalar Date: Date
(see graphql-codegen scalarMap
config) we end up with type errors such as "{} is missing properties from Date toLocaleString, ..."
etc.
Proposal
Replace {}
with unknown
would allow consumers of this library to cast as neccessary.
Issue Analytics
- State:
- Created 2 years ago
- Comments:11 (6 by maintainers)
Top Results From Across the Web
typescript - why can I assign a literal with unknown properties ...
typescript - why can I assign a literal with unknown properties to a variable of type {} - Stack Overflow. Stack Overflow for...
Read more >The unknown Type in TypeScript - Marius Schulz
TypeScript 3.0 introduced a new unknown type which is the type-safe counterpart of the any type.
Read more >Statically Type Unknown Values with TypeScript's unknown ...
In this lesson, we'll go over TypeScript's unknown type. The unknown type is the type-safe counterpart of the any type. Both unknown and...
Read more >Handbook - Literal Types - TypeScript
There are three sets of literal types available in TypeScript today: strings, numbers, and booleans; by using literal types you can allow an...
Read more >no-object-literal-type-assertion - Rule
Disallow object literals to appear in type assertion expressions (default). Casting to `any` and `unknown` is allowed. · Allow using a type assertion...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Is there an equivalent to
graphql-codegen-zod
’szodSchemasMap
?Docs: https://github.com/withshepherd/graphql-codegen-zod#configs
Example: https://github.com/withshepherd/graphql-codegen-zod/blob/main/codegen.yml#L13
Hey, sorry for delay in reply.
I am passing
scalars
like the following into my codegen configuration block:In log output I see the following:
Upon inspecting the generated code anything that was using the Height or Weight scalars are now defined as
definedNonNullAnySchema
.When I use this schema I cannot actually pass the shape of these scalars as I’ve defined because of type errors
"{} is missing properties from Date toLocaleString, ..."
.Ie. The following won’t work
So just to confirm, I think that there are two issues: the default
{}
as “any” doesn’t really provide any flexibility for fallbacks as even the generated code will not compile. There ideally needs to be a way to provide a generator for custom scalars.Ps. Sorry for additional notifications as I accidentally submitted early and closed the issue by mistake.