parjs icon indicating copy to clipboard operation
parjs copied to clipboard

test: add type level tests

Open barona-mika-vilpas opened this issue 1 year ago • 1 comments
trafficstars

Since there is now a new feature for creating parsers with a constant string type (https://github.com/GregRos/parjs/pull/78), this feature should also have tests specifying that the correct type is returned.

There are likely many other cases where type level testing would be beneficial.

barona-mika-vilpas avatar Dec 23 '23 10:12 barona-mika-vilpas

One possibility that could be used for this is https://github.com/arktypeio/arktype/tree/beta/ark/attest, which seems to not require much in terms of extra setup to get the tests running.

I previously implemented constant type inference for implicit parjsers. I haven't merged that in because I'm not sure the added type level complexity is actually useful for users (you can use string("abc") to get a constant type parjser instead).

This was a complex type level feature, and I added type level tests using https://github.com/jest-community/jest-runner-tsd/, which was ok but the developer experience wasn't that great.

barona-mika-vilpas avatar Dec 23 '23 10:12 barona-mika-vilpas

Not sure if I want to go all the way to type level testing yet. Currently the cases should be somewhat nicely covered by using explicit type annotations.

mikavilpas avatar Mar 31 '24 16:03 mikavilpas