Pipe required before narrow

const myFunc = (v: string) => true;
const MyString = type("50<string<200").narrow((s) => myFunc(s));
const myFunc = (v: string) => true;
const MyString = type("50<string<200").narrow((s) => myFunc(s));
Results in error:
error TS2345: Argument of type 'is<MoreThanLength<50> & LessThanLength<200>>' is not assignable to parameter of type 'string'.
error TS2345: Argument of type 'is<MoreThanLength<50> & LessThanLength<200>>' is not assignable to parameter of type 'string'.
However, adding pipe before calling narrow works:
const myFunc = (v: string) => true;
const MyString = type("50<string<200").pipe((s) => s).narrow((s) => myFunc(s));
const myFunc = (v: string) => true;
const MyString = type("50<string<200").pipe((s) => s).narrow((s) => myFunc(s));
Is this intentional?
4 Replies
ssalbdivad
ssalbdivad7mo ago
No those branded types should never be inferred out like that. I'll fix it, thanks!
SynthLuvr
SynthLuvrOP7mo ago
Also seems like I can't use two narrow in a row, I need to do narrow -> pipe -> narrow, with the pipe doing nothing more than return the value untouched
ssalbdivad
ssalbdivad7mo ago
I'll see if I can get all these bug fixes merged today!
SynthLuvr
SynthLuvrOP7mo ago
GitHub
Cannot use narrow before pipe · Issue #969 · arktypeio/arktype
Report a bug 🔎 Search Terms narrow pipe 🧩 Context ArkType version: 2.0.0-dev.13 TypeScript version (5.1+): 5.3.3 Other context you think may be relevant (JS flavor, OS, etc.): 🧑‍💻 Repro const myFun...
Want results from more Discord servers?
Add your server