Object.isPartOfTypeNode crashes with TypeError: Cannot read properties of undefined (reading 'kind')
See original GitHub issueBug Report
🔎 Search Terms
Object.isPartOfTypeNode
and TypeError: Cannot read properties of undefined
🕗 Version & Regression Information
- This is a crash
- This is the behaviour in every version I tried (
4.7.3
,4.7.4
,next
andnightly
which was4.8.0-dev.20220804
for me), and I reviewed the FAQ for entries abouttuple
,recursion
,tail
,elimitation
,depth
andlimitation
- I was unable to test this on prior versions because I use
4.7.3
in my project
⏯ Playground Link
Playground link with relevant code
💻 Code
I reduced the codebase of ttuple to 64 lines.
type AnyArray = readonly any[];
type DigitMapping<T> = {
"0": [];
"1": [T];
"2": [T, T];
"3": [T, T, T];
"4": [T, T, T, T];
"5": [T, T, T, T, T];
"6": [T, T, T, T, T, T];
"7": [T, T, T, T, T, T, T];
"8": [T, T, T, T, T, T, T, T];
"9": [T, T, T, T, T, T, T, T, T];
};
type Multiply10<T extends AnyArray> = [
...T,
...T,
...T,
...T,
...T,
...T,
...T,
...T,
...T,
...T
];
type Add<N1 extends AnyArray, N2 extends AnyArray> = [...N1, ...N2];
type _ToTuple<
V,
S extends string,
T extends AnyArray = []
> = S extends `${infer D}${infer Rest}`
? _ToTuple<
V,
Rest,
Add<Multiply10<T>, DigitMapping<V>[D & keyof DigitMapping<V>]>
>
: [...T, ...V[], ...T];
type ToTuple<V, S extends string> = _ToTuple<V, S>;
type ElementOf<T extends AnyArray> = T extends readonly (infer V)[] ? V : never;
const length = <
T extends AnyArray,
S extends `${number}`,
R = ToTuple<ElementOf<T>, S>
>(
array: T,
condition: `>= ${S}`
): array is R extends T ? R : never => {
const expectedLength = Number(condition.split(" ")[1]);
if (array.length >= expectedLength) {
return true;
}
return false;
};
export { length };
Also the code is available in the branch here – https://github.com/Beraliv/ttuple/pull/22
🙁 Actual behaviour
➜ npm run build
> ttuple@0.2.1 build
> tsc --project tsconfig.json
/Users/beraliv/Documents/Code/ttuple/node_modules/typescript/lib/tsc.js:96887
throw e;
^
TypeError: Cannot read properties of undefined (reading 'kind')
at Object.isPartOfTypeNode (/Users/beraliv/Documents/Code/ttuple/node_modules/typescript/lib/tsc.js:11787:25)
at _loop_15 (/Users/beraliv/Documents/Code/ttuple/node_modules/typescript/lib/tsc.js:50429:51)
at createNormalizedTupleType (/Users/beraliv/Documents/Code/ttuple/node_modules/typescript/lib/tsc.js:50445:31)
at createNormalizedTypeReference (/Users/beraliv/Documents/Code/ttuple/node_modules/typescript/lib/tsc.js:50398:45)
at instantiateTypeWorker (/Users/beraliv/Documents/Code/ttuple/node_modules/typescript/lib/tsc.js:52755:77)
at instantiateTypeWithAlias (/Users/beraliv/Documents/Code/ttuple/node_modules/typescript/lib/tsc.js:52740:26)
at instantiateType (/Users/beraliv/Documents/Code/ttuple/node_modules/typescript/lib/tsc.js:52726:37)
at getMappedType (/Users/beraliv/Documents/Code/ttuple/node_modules/typescript/lib/tsc.js:52449:63)
at /Users/beraliv/Documents/Code/ttuple/node_modules/typescript/lib/tsc.js:52709:92
at Object.map (/Users/beraliv/Documents/Code/ttuple/node_modules/typescript/lib/tsc.js:367:29)
🙂 Expected behaviour
➜ npm run build
> ttuple@0.2.1 build
> tsc --project tsconfig.json
If I replace ToTuple
with _ToTuple
, it starts working 🤯
As I’ve seen example with GetChar
in release notes of TS 4.5, it should be fine to declare it this way – https://devblogs.microsoft.com/typescript/announcing-typescript-4-5/#tailrec-conditional
ℹ️ Additional information
I connected the project to node debugger and could see that in _loop_15
9th element was in the branch of tuple type (after check of isTupleType
), but the length of elements.length + expandedTypes.length
is 11100
(not sure what it means) so it tried to throw an error, but currentNode
was undefined
Issue Analytics
- State:
- Created a year ago
- Comments:8 (2 by maintainers)
Top GitHub Comments
Here’s a simplified repo in 4.7.4 workbench. You can see the error in the devtools console.
The behavior is quite weird. And here is some ways I found to make the error disappear.
fn
.fn
, not function expression._ToTuple
, even it’s not imported anywhere....T,
to 3.0
following the repeated...T,
.V
in_ToTuple
.It sounds reasonable
I will start from “Help Wanted” and “Good First Issue” first, then will jump on this one, if it’s working for you