You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to create a type that can accept either a positive integer or a numeric string, but type validation is not generating the right code even though each side of the union works by itself. Am I doing something wrong?
typeID=(number&Int&Min<0>)|(string&Matches<'/\d+/'>);functionvalidate(user: Assert<ID>){// Your code...}validate('1234');
functionvalidate(user){if(typeofuser!=="number"||user%1!==0||user<0)thrownewError("Expected user to be a number, to be an int, to be greater than 0");if(typeofuser!=="string"||!/d+/.test(user))thrownewError("Expected user to be a string, to match /d+/");}
The text was updated successfully, but these errors were encountered:
Describe the bug
I'm trying to create a type that can accept either a positive integer or a numeric string, but type validation is not generating the right code even though each side of the union works by itself. Am I doing something wrong?
Playground link
https://googlefeud.github.io/ts-runtime-checks?code=C4TwDgpgBAkgIlAvFKAKAdgVwLYCMIBOUAZLOsCVALICW6APAAwB8AlFAD5oDOwBdAc0pUAhsADGACwjd6AcgD0AHQAmAagVy2AbgBQugGaZ044DQD26KADcRAGxoqxEVJm6EAXFACC3dwWB6eDYoAG9dFBQFBSgATXNMInFzFQgAOgzdAF99WwcnYBc5AEYAJgBmABY5Vm0gA
Expected behavior
Should compile into something like this
The text was updated successfully, but these errors were encountered: