'WebStorm/JetBrains error: Arrays missing native functionality in TypeScript
Edit 3: Moved this to the top since it is relevant to the nature of the question. Per AlexWayne's suggestion, I tried a far simpler code sample, and arrived at the same problem. Given the simpler code, I was able to easily compile it using only the tsc utility, and it compiles cleanly in the terminal. That means this is strictly a WebStorm issue, for who knows what reason. Problem isn't really solved, but at least I can keep working and just know to ignore what WebStorm is saying right now.
Before you ask, yes, I've installed @types/node.
This was in the middle of me rewriting it in an attempt to resolve the issue, so forgive me for the unused variable. It started out as a spread to add to lines, but when I started getting an error saying that IBestPracticeStandard[] didn't have a method map, I changed the type signature to Array<IBestPracticeStandard> which had as little effect as you'd expect. I then changed it to a for(const standard of standards) loop, but then I got an error saying IBestPracticeStandard[] a lacked [Symbol.toIterator]() method. My last attempt was what you see, where I turned it into a classic for(let i = 0; i < standards.length; i++) loop, but this too came up with length does not exist on an Array.
I'm at my wits end on this. I know the code itself works, as I imported it from an existing project written in JavaScript. I've been working on this TypeScript overhaul for months, and this is the first time I've encountered such a bizarre error. Any help would be greatly appreciated.
// ./src/interfaces/IBestPracticeStandard.ts
export interface IBestPracticeStandard {
id: number;
name: string;
}
// ./src/interfaces/IConcern.ts
export interface IConcern extends IConcernObject {
_path: string;
_engineTestId: number;
_attribute: string;
_bestPracticeId: number;
_element: string;
_fixType?: unknown;
_needsReview: boolean,
_rawEngineJsonObject: IConcernObject;
_bestPracticeDescription: string;
_severity: number;
_noticeability: number;
_tractability: number;
_bestPracticeDetailsUrl: string;
_bestPracticeStandards: IBestPracticeStandard[];
rawEngineJsonObject: IConcernObject;
toJSON(): IConcernObject;
}
// ./src/AccessibilityConcernMessage.ts
import { IBestPracticeStandard, IConcern } from './interfaces';
export class AccessibilityConcernMessage {
private readonly score: number;
private readonly message: string;
constructor(concern: IConcern) {
const {
_bestPracticeDescription: description,
_bestPracticeStandards: standards,
_bestPracticeDetailsUrl: url,
_severity: severity,
_noticeability: noticeability,
_tractability: tractability,
_rawEngineJsonObject: {
attribute: attr,
attributeDetail: detail,
path,
fingerprint: { css }
}
} = concern;
const lines: string[] = [
`Attribute: ${attr}`,
`${detail}\nBest Practice: ${description}`,
url
];
for(let i = 0; i < standards.length; i++) {
const { name } = standards[i];
lines.push(`- ${standard.name}`);
}
this.score = (severity + noticeability + tractability) / 30;
this.message = `${lines.join('\n\t')}\nFound At Path: ${path}\nCSS Locator: ${css}`
}
toString(): string {
return this.message;
}
valueOf(): number {
return this.score;
}
}
Edit: Adding to say I'm getting additional TypeScript errors that say string[] doesn't have method push, no index signature on IBestPracticeStandard[]
Edit 2: Adding my tsconfig.json
{
"compilerOptions": {
/* Visit https://aka.ms/tsconfig.json to read more about this file */
/* Projects */
"incremental": true, /* Enable incremental compilation */
/* Language and Environment */
"target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
/* Modules */
"module": "commonjs", /* Specify what module code is generated. */
"moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
"baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
/* JavaScript Support */
/* Emit */
"declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
"declarationMap": true, /* Create sourcemaps for d.ts files. */
"sourceMap": true, /* Create source map files for emitted JavaScript files. */
"outDir": "./dist", /* Specify an output folder for all emitted files. */
/* Interop Constraints */
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
/* Type Checking */
"strict": true, /* Enable all strict type-checking options. */
"noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied `any` type.. */
"noImplicitThis": true, /* Enable error reporting when `this` is given the type `any`. */
"alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
"noUnusedLocals": true, /* Enable error reporting when a local variables aren't read. */
"noUnusedParameters": true, /* Raise an error when a function parameter isn't read */
/* Completeness */
"skipLibCheck": true /* Skip type checking all .d.ts files. */
}
}
Solution 1:[1]
It seems, as AlexWayne pointed out, that WebStorm had silently devolved into a bad state. Closing it and reopening the IDE re-initialized all of the internal workings and it is now registering everything properly. Thanks to the quick and helpful comments
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Solonotix |

