-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Closed
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug
Description
Bug Report
π Search Terms
template literal wrong infer
π Version & Regression Information
Tested in version 4.1.5, 5.2.3, 4.3.5, 4.4.0, 4.5.2, 4.6.0 nightly, everywhere the same behaviour.
β― Playground Link
Playground link with relevant code
π» Code
type d8 = `1234` extends `${number}${infer T1}${number}` ? T1 : never; //'2'
type d9 = `2234` extends `${number}${infer T1}${number}` ? T1 : never; //neverπ Actual behavior
d9 is computed as never.
π Expected behavior
d9 should be computed as '2'.
After debugging a bit inferFromLiteralPartsToTemplateLiteral in checker.ts, it seems p = getSourceText(s).indexOf(delim, p) searches for 2 in a targetTexts being ['', 2, ''] yielding a wrong result.
It's not clear to me what the actual algorithm should be here as I haven't found any spec or fundamental rules behind inferring template placeholders like above.
Autumn-oneMartinJohns
Metadata
Metadata
Assignees
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug