Closed Veetaha closed 5 years ago
Wow the repo ts-typedefs is awesome! Thanks a lot!!
In fact I already know how to check any
and I am using the similar mechanism as you provide. Here is the code: https://github.com/hjkcai/typesafe-joi/blob/feature/split-files/test/util.ts . But your implementation is much smarter and can be used in more situations.
However, I am stuck in Microsoft/TypeScript#30794 now. I am trying another way to implement typesafe-joi with (maybe) less type recursion.
BTW do you know how to force TypeScript to expand some complex deferred type? The evaluation of mapped types are sometimes (I don't know the exact point) deferred. Hovering on this kind of type looks horrible.
@hjkcai Thank you too))
However, I am stuck in Microsoft/TypeScript#30794 now
Same issue with heap-overflow
here. I can't generate enough instances of the type without crashing the tsc
. I tried to create my own type-safe schema validator, and stopped at writing documentation, but I think there is no need for it while this package exists)
BTW do you know how to force TypeScript to expand some complex deferred type?
Unfortunately, I've never wondered about it. Most of the time complex types are expanded in-place when I hover over them, but not always. I didn't pay much attention to it because I consider forcing them expand to be impossible and not that important. Maybe you should create a question
issue at Microsoft/TypeScript and/or Stackoverflow, it would be interesting also for me to get an answer from developers.
@Veetaha I have published typesafe-joi 2.0.0 alpha version, which uses IsAny
in this situation. And I am sure it is more stable now (I don't want to submit an issue to TypeScript about typesafe-joi anymore). Please have a try! If you have any idea or found any bug, feel free to open another issue 😀
I've just read your
README.md
and haven't even downloaded your package yet, but I see you are confused stating the followingThere actually is a way to check for
any
type. Type expressionboolean extends (T extends never ? true : false) ? true : false
evaluates totrue
only whenT
is ofany
type, so that bothtrue
andfalse
branch in the inner conditions are matched and their union (namelyboolean
) is returned, which you ultimatelly check in the outer condition. You may use this definition or get an existing one fromts-typedefs
package that exposes such handy definitions asIs[Not]Any<>
,Is[Not]Unknown<>
,Is[Not]Never<>
and much more. Here is the code forIsAny<>
type.