Closed as not planned
Closed as not planned
Description
🔎 Search Terms
intersection template type never
🕗 Version & Regression Information
- I was unable to test this on prior versions than 4.5 because
// ^?
does not work on typescript playground
I think this is bug since template literal type is introduced in 4.1.
⏯ Playground Link
💻 Code
function any(): any { throw null; }
const test5: `miauth/${string}/check` & `${string}/timeline` = any();
// ^?
// this should be never but does not
🙁 Actual behavior
`miauth/${string}/check` & `${string}/timeline`
will remain `miauth/${string}/check` & `${string}/timeline`
not coming never
would cause problem with Indexed Access Types
function any(): any { throw null; }
type Endpoints = {
'test/timeline': 0,
'test2/timeline': 0,
'other endpoint': 2,
[ep: `miauth/${string}/check`]: 1, // no error at test2 if comment
}
type TimelineEndpoints = keyof Endpoints & `${string}/timeline`;
const test2: Endpoints[TimelineEndpoints] = any();
const test3: 0 = test2;
// This assignment should not have type errors,
// but because `miauth/${string}/check` & `${string}/timeline` is not never,
// test2 become 0|1 so we cannot assign test2 to test3.
🙂 Expected behavior
`miauth/${string}/check` & `${string}/timeline`
should become never
and Endpoints[TimelineEndpoints]
in snippet above should become 0
Additional information about the issue
Of course, we cannot assign variable typed `miauth/${string}/check`
to `${string}/timeline`
and vice versa.
function any(): any { throw null; }
const test0: `miauth/${string}/check` = any();
const test1: `${string}/timeline` = test0; // error here, as expected
Real world case: misskey-dev/misskey#14885 (comment)