Removing the type guards?
See original GitHub issueSaw the note about removing check
, but if it is simply safeParse().success
, why can we not implement it that way in the base type? I assume this has already been tried, but if there is a problem with that, it would be helpful to know what the problem is so that I don’t accidentally reproduce the issue in my own usage.
Issue Analytics
- State:
- Created 3 years ago
- Comments:5
Top Results From Across the Web
TypeScript: How Type Guards Can Help You Get Rid of 'as'
In this article, I will go into more detail about “as” and explain how to avoid it by using type guards, which represent...
Read more >Documentation - Narrowing - TypeScript
It looks at these special checks (called type guards) and assignments, ... and TypeScript still correctly removes null from the type of strs...
Read more >Type guard removing string literal types - Stack Overflow
When creating a TS type guard, it seems like string literals are removed from the narrowed type once you add undefined or null...
Read more >How To Do Anything in TypeScript With Type Guards
Remove all values null or undefined values from array. Using the isDefined type guard we just defined, we can use it with the...
Read more >Keeping TypeScript Type Guards safe and up to date (a ...
Type guards allow us to check that a runtime, unknown object (think ... is not shared with other scopes—is removed at compile time...
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
Wrote this little wrapper that seems to do the right thing:
— But still not clear why this can’t be how
ZodType#check
is implemented to avoid having to import this helper when using aZodSchema
Finally I used the same way as @scotttrinh did. It works nicely with
next-rest
.Full context here: https://github.com/joeltg/next-rest/issues/1