-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptCrashFor flagging bugs which are compiler or service crashes or unclean exits, rather than bad outputFor flagging bugs which are compiler or service crashes or unclean exits, rather than bad output
Milestone
Description
Bug Report
No error or wrong in the editor when coding.
C:\XXX\node_modules\typescript\lib\tsc.js:90672
throw e;
^
TypeError: Cannot read property 'length' of undefined
at elaborateDidYouMeanToCallOrConstruct (C:\XXX\node_modules\typescript\lib\tsc.js:49543:72)
at elaborateError (C:\XXX\node_modules\typescript\lib\tsc.js:49507:20)
at checkTypeRelatedToAndOptionallyElaborate (C:\XXX\node_modules\typescript\lib\tsc.js:49495:32)
at getSignatureApplicabilityError (C:\XXX\node_modules\typescript\lib\tsc.js:59070:26)
at resolveCall (C:\XXX\node_modules\typescript\lib\tsc.js:59374:37)
at resolveCallExpression (C:\XXX\node_modules\typescript\lib\tsc.js:59704:20)
at resolveSignature (C:\XXX\node_modules\typescript\lib\tsc.js:60026:28)
at getResolvedSignature (C:\XXX\node_modules\typescript\lib\tsc.js:60046:26)
at checkCallExpression (C:\XXX\node_modules\typescript\lib\tsc.js:60156:29)
at checkExpressionWorker (C:\XXX\node_modules\typescript\lib\tsc.js:62512:28)
🔎 Search Terms
🕗 Version & Regression Information
My ts version is 4.4.3
.
(I updated ts to the latest version after the problem occurred, and I don't remember the version I used before)
- This is a crash
⏯ Playground Link
Can't provide.
💻 Code
This is the smallest version I can simplify:
/* NOTE tsconfig.json:
{
"compilerOptions": {
"target": "ESNext",
"module": "commonjs",
"strict": true,
}
}
*/
type TMessage<Type extends string = string> = {
type: Type
}
type TMessageMap<_Type extends string = string> = {
[K in _Type]: {
msg: TMessage
chain: keyof TMessageMap<_Type> | null
}
}
type GetMsg<
MsgMap extends TMessageMap,
Type extends keyof MsgMap = keyof MsgMap
> = MsgMap[Type]["msg"]
type GetChain<
MsgMap extends TMessageMap,
Type extends keyof MsgMap = keyof MsgMap
> =
MsgMap[Type]["chain"] extends keyof MsgMap ?
GetMsg<MsgMap, MsgMap[Type]["chain"]>
: null
export type TReply<
MsgMap extends TMessageMap,
LocalMsg extends GetMsg<MsgMap> | null,
HandleMsg extends GetMsg<MsgMap>,
RemoteMsg extends GetMsg<MsgMap> | null
= (
LocalMsg extends GetMsg<MsgMap> ?
GetChain<MsgMap, LocalMsg["type"]>
: null
)
> = (
RemoteMsg extends GetMsg<MsgMap> ?
Answer<
MsgMap,
RemoteMsg,
HandleMsg
>
: Handle<MsgMap, HandleMsg>
)
type Answer<
MsgMap extends TMessageMap,
RemoteMsg extends GetMsg<MsgMap>,
HandleMsg extends GetMsg<MsgMap>
> = {
answer: (callback: (msg: RemoteMsg) => GetChain<MsgMap, RemoteMsg["type"]>) => TReply<
MsgMap,
GetChain<MsgMap, RemoteMsg["type"]>,
HandleMsg
>
}
type Handle<
MsgMap extends TMessageMap,
HandleMsg extends GetMsg<MsgMap>
> = {
handle: <Msg extends HandleMsg>(callback: (msg: Msg) => GetChain<MsgMap, Msg["type"]>) => void
}
export function fn<
MsgMap extends TMessageMap,
/* NOTE
if use `keyof MsgMap`, then compilation will continue
like this:
Listen extends keyof MsgMap,
Handle extends keyof MsgMap
*/
Listen extends Extract<keyof MsgMap, string>,
Handle extends Extract<keyof MsgMap, string>
>(
) {
type TCallback<Type extends Listen> = (
getReply: () => TReply<
MsgMap,
null,
GetMsg<MsgMap, Handle>,
GetMsg<MsgMap, Type>
>
) => void
(1 as unknown as TCallback<Listen>)(() => {
return {} as unknown as TReply<
MsgMap,
GetMsg<MsgMap, Listen>,
GetMsg<MsgMap, Handle>
>
/* NOTE ↑↑↑
I know `as` is used incorrectly here,
and if correct it, then compilation will continue
*/
})
}
🙁 Actual behavior
Build process interrupt.
🙂 Expected behavior
Output file or print error.
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptCrashFor flagging bugs which are compiler or service crashes or unclean exits, rather than bad outputFor flagging bugs which are compiler or service crashes or unclean exits, rather than bad output