Open slyofzero opened 2 months ago
We need a way to reproduce this
We need a way to reproduce this
I have updated the original issue with reproduction steps and additional information about how I have tested it
tsc
is also not terminating in a reasonable amount of time. Bisecting...
Bisects to #57345
Using just grammy
as a dependency:
import { Bot } from "grammy";
export const teleBot = new Bot("");
teleBot.on(":animation", c => c);
Before
Identifiers: 57697
Symbols: 37871
Types: 9556
Instantiations: 240994
Memory used: 84999K
Assignability cache size: 18439
Identity cache size: 128
Subtype cache size: 0
Strict subtype cache size: 0
I/O Read time: 0.01s
Parse time: 0.19s
ResolveModule time: 0.02s
ResolveTypeReference time: 0.00s
ResolveLibrary time: 0.01s
Program time: 0.25s
Bind time: 0.07s
Check time: 0.34s
After
Identifiers: 53327
Symbols: 38110
Types: 535156
Instantiations: 243474
Memory used: 2670146K
Assignability cache size: 35533
Identity cache size: 116
Subtype cache size: 0
Strict subtype cache size: 42
I/O Read time: 0.01s
Parse time: 0.14s
ResolveModule time: 0.02s
ResolveTypeReference time: 0.01s
ResolveLibrary time: 0.01s
Program time: 0.21s
Bind time: 0.07s
Check time: 30.54s
Basically stuck here:
import { Filter, FilterQuery } from "grammy";
import { Context } from "grammy/out/context.js";
// Uncomment constraint to repro
type MiddlewareFn<C /*extends Context*/> = (ctx: C) => void;
declare function on<Q extends FilterQuery>(middleware: MiddlewareFn<Filter<Context, Q>>): void;
and there go my weekend plans... π
@ahejlsberg assigning to you since #57343 also was, but sounds like @Andarist might be working on it?
Bisects to #57345
what seems to be the issue here? grammy.js is at fault?
Bisects to https://github.com/microsoft/TypeScript/pull/57345
what seems to be the issue here? grammy.js is at fault?
No, TS is. It's a regression caused by a change that was made in the linked PR (#57345), which was found via git bisect
. grammy
just happens to be the module that triggers the bug.
@RyanCavanaugh I'm unable to reproduce with the examples here and here. The second example (after uncommenting the constraint) shows this:
Files: 53
Lines: 48693
Identifiers: 51490
Symbols: 34834
Types: 3750
Instantiations: 87521
Memory used: 70217K
I/O read: 0.01s
I/O write: 0.00s
Parse time: 0.23s
Bind time: 0.07s
Check time: 0.14s
Emit time: 0.01s
Total time: 0.45s
This is with the compiler in main branch, following tsc -init
and npm i grammy
. Am I missing something?
@ahejlsberg Try this? https://github.com/RyanCavanaugh/repro-58373
Relevant numbers on main
Files: 59
Lines of Library: 36690
Lines of Definitions: 13738
Identifiers: 53544
Symbols: 36350
Types: 532823
Instantiations: 235429
Memory used: 2693736K
Assignability cache size: 35030
Check time: 27.66s
Total time: 27.95s
Ok, I can reproduce with your repo. The difference is you're using an older version of grammy
, 1.20.3. Current version on NPM is 1.22.4 and it doesn't have a problem.
See https://github.com/grammyjs/grammY/pull/553. Looks like this is a known issue that was fixed by in the latest grammy
. I'd still be interested in knowing why #57345 slowed down the old types, but appears there's a simple workaround.
I'm still working on minimizing this further but I want to share a single-file repro created based on the code from grammy. Some parts of this probably no longer make sense (I remove bits that make sense for what their types want to achieve but which are not relevant for the repro):
= Q extends `${infer L1}:${infer L2}:${infer L3}` ? `${CollapseL1}:${CollapseL2 }:${L3}` : Q extends `${infer L1}:${infer L2}` ? `${CollapseL1 }:${CollapseL2 }` : CollapseL1 ; type FilterQuery = InjectShortcuts; type ExpandL1= S extends L1Shortcuts ? (typeof L1_SHORTCUTS)[S][number] : S; type ExpandL2= S extends L2Shortcuts ? (typeof L2_SHORTCUTS)[S][number] : S; type ExpandShortcuts= Q extends `${infer L1}:${infer L2}:${infer L3}` ? `${ExpandL1}:${ExpandL2 }:${L3}` : Q extends `${infer L1}:${infer L2}` ? `${ExpandL1 }:${ExpandL2 }` : ExpandL1 ; type FilteredContextCore = Record<"update", U> & AliasProps>; type FilteredContext = C & FilteredContextCore; type PerformQuery = U extends unknown ? FilteredContext : never; type Filter = PerformQuery< C, RunQuery > >; type L1Equivalents = { message: "from"; edited_message: "from" | "edit_date"; channel_post: "sender_chat"; edited_channel_post: "sender_chat" | "edit_date"; }; type TwinsFromL1 = L1 extends KeyOf ? L1Equivalents[L1] : L2; type L2Equivalents = {} type TwinsFromL2 = L1 extends KeyOf ? L2 extends KeyOf ? L2Equivalents[L1][L2] : L2 : L2; type AddTwins = | TwinsFromL1 | TwinsFromL2 type L2ShallowFragment = Record< AddTwins , NotUndefined >; type L2Fragment = L2 extends unknown ? Record , NotUndefined> : never; type L2Discriminator = [L2] extends [ never, ] ? L2ShallowFragment : Combine , L2>; type L1Parts = Q extends `${infer L1}:${string}` ? L1 : Q; type L2Parts< Q extends string, L1 extends string, > = Q extends `${L1}:${infer L2}:${string}` ? L2 : Q extends `${L1}:${infer L2}` ? L2 : never; type L1Fragment= L1 extends unknown ? Record>> : never; type L1Discriminator = Combine< L1Fragment, L1 >; type Combine = U extends unknown ? U & Partial, undefined>> : never; type RunQuery = L1Discriminator>; type MiddlewareFn= (ctx: C) => void; declare function on ( middleware: MiddlewareFn>, ): void; ```
I will continue working on this - so far, what I was able to notice is that AliasProps
being a renaming mapped type impacts this.
π Search Terms
TS intellisense not working, TS hangs up entire PC, Type inference not working
π Version & Regression Information
β― Reproduction steps
To reproduce this issue please clone the following repository - https://github.com/slyofzero/TONBuyBot Install the packages using pnpm -
pnpm i
Visit the file -./src/bot/commands/index.ts
π» Code
The file code in question is very tame -
The above code is used to setup a telegram bot's commands using grammy.js
π Actual behavior
Update - The issue only occurs when I open the
./src/bot/commands/index.ts
file of the repository I share above in reproduction steps.Uptil yesterday night VSCode and Typescript Intellisense worked fine but now types of variables upon hovering are indefinitely stuck at "Loading..."
This is followed by a high spike in CPU and RAM usage
The icon to the bottom right showing TS server status keeps spinning followed followed by the spike in CPU and RAM usage mentioned above.
Because of all these issues, using the computer with the project on is next to impossible. Typescript syntax errors, Intellisense, or Type inference, nothing works. I first tried uninstalling and reinstalling VSCode but that didn't fix it. I formatted by hard drive and reinstalled my OS but the problem still persists. I have gone through the below two issues that sounds similar to my problem but haven't found a fix yet.
https://github.com/microsoft/TypeScript/issues/35512 https://github.com/microsoft/vscode/issues/87870
π Expected behavior
The expected behaviour would be smooth Intellisense, type inference, and an average usage of CPU and RAM not affecting other functionalities of my PC.
Additional information about the issue
I have tried this issue on two different devices and two different OS and been able to reproduce on both.
First device was an i3, 8GB RAM Dell Inspiron 5482 with Windows 10 Second device is an AMD Ryzen 7 6800, 32GB RAM, 8GB RTX 3070, Lenovo Legion 5 Pro with Windows 11