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'd like to be able to provide a type that limits a string to be of a certain format, and then re-use that type in multiple places to enforce the same formatting everywhere.
Typia Version: 5.2.4 & typia@next
Expected behavior: A type of the form type T = string & tags.Pattern<'.*'>; can be used anywhere and have the same validation applied.
Actual behavior: A type of the above form works when used as the property of a
It seems like this primarily applies to object keys, where some default test is applied to keys and it ignores any other tests that type should have applied to it. I assumed this was maybe due to the type being an alias of a primitive (or something like that), but the type itself works fine if used in any other instance except as the key of an object.
Notably, this validation does work for maps, but not Records or using indexable types.
This is related to #725, but my type alias is using tags to add extra conditions. I would have assumed that could work?
importtypia,{tags}from"typia";typeCustomId=string&tags.Pattern<'^[0-9a-z]{16}$'>;// worksconstvalidateId=typia.createIs<CustomId>();interfaceSomeValue{id: CustomId;attribute: number;}// worksconstvalidateSomeValue=typia.createIs<SomeValue>();typeSomeOtherValue={id: CustomId;otherAttribute: number;}// worksconstvalidateSomeOtherValue=typia.createIs<SomeOtherValue>();typeValueCollection=Record<CustomId,SomeValue>;// does not workconstvalidateCollection=typia.createIs<ValueCollection>();interfaceOtherValueCollection{[key: CustomId]: SomeOtherValue;}// does not workconstvalidateOtherCollection=typia.createIs<OtherValueCollection>();
Comparison to Map:
importtypia,{tags}from"typia";typeCustomId=string&tags.Pattern<'^[0-9a-z]{16}$'>;// workstypia.createIs<Map<CustomId,number>>();// does not worktypia.createIs<Record<CustomId,number>>();// does not worktypia.createIs<{[key: CustomId]: number}>();
The text was updated successfully, but these errors were encountered:
📝 Summary
I'd like to be able to provide a type that limits a string to be of a certain format, and then re-use that type in multiple places to enforce the same formatting everywhere.
typia@next
type T = string & tags.Pattern<'.*'>;
can be used anywhere and have the same validation applied.It seems like this primarily applies to object keys, where some default test is applied to keys and it ignores any other tests that type should have applied to it. I assumed this was maybe due to the type being an alias of a primitive (or something like that), but the type itself works fine if used in any other instance except as the key of an object.
Notably, this validation does work for maps, but not Records or using indexable types.
This is related to #725, but my type alias is using tags to add extra conditions. I would have assumed that could work?
⏯ Playground Link
https://typia.io/playground/?script=JYWwDg9gTgLgBDAnmYBDANHA3g1BzAZzgF84AzKCEOAIiRVRoG4AoF+gUzgGEBXAmFQCSAEzgBeOAKjAAdnjgAyXIQB0ABVQwYHKLIA8AcgB6AbQAMAWgCcqSwC8AulgCMANmIASQwD5WLAHoAuAB3aABrAhYAYwhZATgAN1QAG2ARLQ5RCQRkNFVoqA5MoQJ9PgFhER8ACgBKfzkdKDJUaK4AZSoOADVU3i4sFjgRuHSALh5+QRBRVlG4LRgZACNeHUnZXhAV3VZiNiDQiKjY+PhktIydLpBe-q5JenzC4p1S-Vv7lIHahrZOHAvgB5GAAC10fR+j2ww1GEymlVmInmowg4N0AEFtKt1hxNttdlB9odgmEoJEYnEEpd0pkQRioFCBjlnqgCkUSmUGRCmQ8-v5AcyONwICkUhxojBgHEcgAlSXQETlaZVTBfYV+UlwEQQDhEWTo44UqnnJKpOk6UXiyXS2VPPLs15c-TC60SqUy2QCthNXStdpwUG8t1ij122SwhamcIcRCTCozUSOSY8yEPEmBYK6-VwQ3wcnhU00i3XDjB3Tu21e1mOjlvLJlCt86FVz1xAVAA
Comparison with
Map
:https://typia.io/playground/?script=JYWwDg9gTgLgBDAnmYBDANHA3g1BzAZzgF84AzKCEOAIiRVRoG4AoF+gUzgGEBXAmFQCSAEzgBeOAKjAAdnjgAyXIQB0ABVQwYHKLIA8AcgB6AbQAMAWgCcqSwC8AulgCMANmIASQwD5WLAHoAuAB3aABrAnZkNFUAYygOLQ4hAn0AWVQwfT4BYRFMWV4QACNdHx8ACgBKfyC4EQgOIlkIeDCocOiGeMTk1P0AJQ446BEc-kEQUULisqgKmrrgxua4VvaI7tiEpJ0BrBY4Y7hTcI5EAC4eSfzHa6LS3RZiKtqgA
💻 Code occuring the bug
Comparison to
Map
:The text was updated successfully, but these errors were encountered: