TypeScript interface is incomplete
See original GitHub issueIn particular, ParserOptions
does implement all available options (e.g., length can be a string or function too).
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:7 (6 by maintainers)
Top Results From Across the Web
typescript - How to use incomplete types - Stack Overflow
I would like to use T as the type for the properties parameter since it has the type information I want already, but...
Read more >Can wrongly assign object with incomplete mapped type to ...
Based on how this applies to interfaces but not type aliases, I'd guess this is a bug with interface type parameter variance probing....
Read more >Documentation - Utility Types - TypeScript
Partial <Type> ... Constructs a type with all properties of Type set to optional. This utility will return a type that represents all...
Read more >Intellij creates incomplete method on "Implement all members ...
The bundled "JavaScript and TypeScript" repeatedly generates incorrect ... For instance, I've got this method defined in an interface:
Read more >No More Confusion About TypeScript's Type and Interface
TypeScript type vs interface, Types vs interfaces in TypeScript, TypeScript type, TypeScript interface, difference between interface and type.
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 FreeTop 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
Top GitHub Comments
This is a very nice feature to have. It is not impossible to implement – data validation libraries have been doing this for quite some time. However, I have been reading Zod’s source code (looks like very advanced stuff), but I haven’t yet figured out a way to recreate the same effect. Also, there are other validation libraries, it’s just that Zod is the one I’m most familiar with.
See below for an example using Zod, using the IPv4 header parsing example.
Notes:
parsedIpHeader
is theany
object parsed bybinary-parser
.validatedIpHeader
,validatedIpHeaderV2
, andvalidatedIpHeaderV3
are the type-inferred objects validated byzod
.binary-parser
, and maybe we can have something like Whereend()
marks the end of the call chain, and it’s the only place where the parser types are inferred.validatedIpHeader
:Example (long block of code)
@cmdcolin Yes, it is expected but a type-safe interface would be very cool. Do you have any good ideas on how to implement it?