-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Open
Description
π Search Terms
crash template
π Version & Regression Information
This issue occurrs with 5.9.3, 6.0.0-beta, and results in a system OOM instead of V8 crash when using the latest tsgo.
β― Playground Link
π» Code
This issue is minimally reproducible with a single line:
type Strip<T extends string> = T extends `${infer Rest}.` ? Strip<Rest> : T;My use case is more complicated:
/**
* Flatten an object structure into a set of "keys".
*
* @example
* ```ts
* type example = FlattenKeys<{ h: { s: { l: 1; v: 2 } } }>;
* type result = "h" | "h.s" | "h.s.l" | "h.s.v";
* ```
*/
export type FlattenKeys<O> = {
[K in keyof O & (string | number)]: O[K] extends Record<any, any>
? K | `${K}.${FlattenKeys<O[K]>}`
: K;
}[O extends readonly any[]
? keyof O & `${number}`
: keyof O & (string | number)];
export type KeySeparator = '.' | '[' | ']';
/**
* Get a value using a path of property keys.
*/
export type GetByString<
Data,
Path extends string | number = FlattenKeys<Data>,
> = Path extends `__proto__${`${KeySeparator}${string | number}` | ''}`
? never
: Path extends `${KeySeparator}${infer Rest}`
? GetByString<Data, Rest>
: Path extends `${infer Rest}${KeySeparator}`
? GetByString<Data, Rest>
: Path extends `${infer Key extends keyof Data & (string | number)}${KeySeparator}${infer Rest}`
? GetByString<Data[Key], Rest>
: Path extends keyof Data & (string | number)
? Data[Path]
: undefined;
interface Duck {
taxonomy: {
genus: 'anas';
species: 'platyrhynchos';
};
}
type DuckSpecies = GetByString<Duck, 'taxonomy.species'>; // 'platyrhynchos'π Actual behavior
V8 runs out of memory
$ npx tsc
<--- Last few GCs --->
[424790:0x56029fb82000] 22925 ms: Scavenge (interleaved) 4066.4 (4075.8) -> 4060.5 (4092.8) MB, pooled: 0 MB, 8.24 / 0.00 ms (average mu = 0.375, current mu = 0.357) allocation failure;
[424790:0x56029fb82000] 23581 ms: Mark-Compact (reduce) 4060.6 (4092.8) -> 4060.3 (4063.0) MB, pooled: 0 MB, 510.79 / 0.00 ms (+ 7.7 ms in 2 steps since start of marking, biggest step 5.0 ms, walltime since start of marking 527 ms) (average mu = 0.354
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
----- Native stack trace -----
1: 0x7f9d11a42aaf node::OOMErrorHandler(char const*, v8::OOMDetails const&) [/lib64/libnode.so.137]
2: 0x7f9d12e5e1f4 [/lib64/libnode.so.137]
3: 0x7f9d12e5e2f6 [/lib64/libnode.so.137]
4: 0x7f9d1314a77b [/lib64/libnode.so.137]
5: 0x7f9d1314a7ab [/lib64/libnode.so.137]
6: 0x7f9d1314aa4f [/lib64/libnode.so.137]
7: 0x7f9d131609ec [/lib64/libnode.so.137]
8: 0x7f9d13164e14 [/lib64/libnode.so.137]
9: 0x7f9d13db44f7 [/lib64/libnode.so.137]
π Expected behavior
It works, or better yet gives a TSC error.
Additional information about the issue
While the single-line example is undoubtedly poor code, I think it should never cause a system OOM or the compiler to crash like this.
In fact, tsgo's behavior is more troubling and could result in a DOS.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels