gkz/type-check

Regression in 0.4.0

piranna opened this issue · 3 comments

With version 0.3.0, the string warning is valid with the next code:

const {parsedTypeParse} = require('levn')
const {parseType} = require('type-check')

const entry = '(String | Number, Undefined | {...})'
const ruleTypeDesc = `${entry} | [${entry}] | {...}`

const ruleType = parseType(ruleTypeDesc)

if(typeof rules === 'string') rules = parsedTypeParse(ruleType, rules)

After upgrading to 0.4.1, I get the next error:

Value "warning" does not type check against [{"structure":"tuple","of":[[{"type":"String"},{"type":"Number"}],[{"type":"Undefined"},{"structure":"fields","of":{},"subset":true}]]},{"structure":"array","of":[{"structure":"tuple","of":[[{"type":"String"},{"type":"Number"}],[{"type":"Undefined"},{"structure":"fields","of":{},"subset":true}]]}]},{"structure":"fields","of":{},"subset":true}].

What I was trying to do, is that the warning string gets parsed and converted as one-tuple with a warning string as its first and only value (or two-tuple of string-undefined, that's the same for this use case).

I've done a bisect and found the first commit where tests of my project are failling is at 6a2c33c

With the (String | Number, Undefined | {...}) | [(String | Number, Undefined | {...})] | {...} type, [("warning")] works, and the same for ["warning"], but it doesn't work for ("warning").

Any update on this?