-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeError: Cannot read properties of undefined (reading '0') - weird errors #1427
Comments
Thanks for posting! I tried playing a bit with experimental decorators locally but couldn't figure out how to reproduce this error. 😕 @rubiesonthesky I'd be happy to sign an NDA and take a look at the code privately. Otherwise, without a reproduction, I'm stuck here. |
I think, version 0.7.3 fixed the problem where with messing up imports. I'm still getting a lot errors in the console though with same message |
I found a way to reproduce this! :D Use typestat in this repo with {
"fixes": {
"incompleteTypes": true
},
"include": [
"src/**/*.{ts,tsx}"
],
"projectPath": "tsconfig.json"
} Error Error in //TypeStat/src/mutators/builtIn/fixIncompleteTypes/fixIncompleteReactTypes/fixReactPropFunctionsFromCalls/createFunctionCallTypesMutation.ts at node 'interface CombinedFunctionType {
parameters: ts.Type[][];
returnValue?: ts.Type[];
}' (position 413):
TypeError: Cannot read properties of undefined (reading '0')
at expandReferencesForGenericTypes (/.npm/_npx/42ab35185b79194c/node_modules/typestat/src/mutators/builtIn/fixIncompleteTypes/fixIncompleteInterfaceOrTypeLiteralGenerics/collectGenericNodeReferences.js:83:77)
at collectGenericNodeReferences (/.npm/_npx/42ab35185b79194c/node_modules/typestat/src/mutators/builtIn/fixIncompleteTypes/fixIncompleteInterfaceOrTypeLiteralGenerics/collectGenericNodeReferences.js:39:56)
at visitInterfaceOrTypeLiteral (/.npm/_npx/42ab35185b79194c/node_modules/typestat/src/mutators/builtIn/fixIncompleteTypes/fixIncompleteInterfaceOrTypeLiteralGenerics/index.js:39:99)
at tryGetMutation (/.npm/_npx/42ab35185b79194c/node_modules/typestat/src/mutators/collectMutationsFromNodes.js:50:16)
at visitNode (/.npm/_npx/42ab35185b79194c/node_modules/typestat/src/mutators/collectMutationsFromNodes.js:37:30)
at visitNodes (/.npm/_npx/42ab35185b79194c/node_modules/typestat/node_modules/typescript/lib/typescript.js:28303:24)
at forEachChildInSourceFile (/.npm/_npx/42ab35185b79194c/node_modules/typestat/node_modules/typescript/lib/typescript.js:28946:18)
at Object.forEachChild (/.npm/_npx/42ab35185b79194c/node_modules/typestat/node_modules/typescript/lib/typescript.js:28388:37)
at collectMutationsFromNodes (/.npm/_npx/42ab35185b79194c/node_modules/typestat/src/mutators/collectMutationsFromNodes.js:44:8)
at fixIncompleteInterfaceOrTypeLiteralGenerics (/.npm/_npx/42ab35185b79194c/node_modules/typestat/src/mutators/builtIn/fixIncompleteTypes/fixIncompleteInterfaceOrTypeLiteralGenerics/index.js:34:124) |
I'm seeing this also in mutation tests.
import ts from "typescript";
(function () {
interface FunctionCallType {
parameters?: (ts.Type | undefined)[];
returnValue?: ts.Type;
}
interface CombinedFunctionType {
parameters: ts.Type[][];
returnValue?: ts.Type[];
}
const functionCallTypes: FunctionCallType[] = [];
const combinedType = functionCallTypes.reduce<CombinedFunctionType>(
(accumulator, functionCallType) => {
return {
parameters: combineParameters(
undefined,
accumulator.parameters,
functionCallType.parameters,
),
returnValue: collectOptionals(accumulator.returnValue, [
functionCallType.returnValue,
]).filter(isNotUndefined),
};
},
{
parameters: [],
returnValue: [],
},
);
const combineParameters = (
request: unknown,
previous: ts.Type[][],
next: (ts.Type | undefined)[] | undefined,
) => {
if (next === undefined) {
return previous;
}
const combined: ts.Type[][] = [];
let i: number;
for (i = 0; i < previous.length; i += 1) {
combined.push([...previous[i]]);
if (i < next.length && next[i] !== undefined) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
combined[i].push(next[i]!);
}
}
for (i; i < next.length; i += 1) {
if (next[i] !== undefined) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
combined.push([next[i]!]);
}
}
return combined;
};
const collectOptionals = <T>(
...arrays: (readonly T[] | undefined)[]
): T[] => {
const results: T[] = [];
for (const array of arrays) {
if (array !== undefined) {
results.push(...array);
}
}
return results;
};
const isNotUndefined = <T>(item: T | undefined): item is T =>
item !== undefined;
})(); This could probably be simplified a lot from this. |
🐛 Bug Report
Actual Behavior
There are a lot errors like this when I try to run the tool
Also, some places imports are overwritten like this. Not sure if these are connected. They do not seem to, but you never know.
Expected Behavior
Not throw weirds errors without explanation.
Reproduction
I have been trying with few different setups, but here is latest
Unfortunately, this is not a repo I can share straight away. It's Angular project, so there are legacy/experimental decorators for example. Strict options look like this
I think this code that the error points to this.
I have tried to restrict to run only on some files, and I suspect that Angular decorators are one culprit here.
The text was updated successfully, but these errors were encountered: