TS18028
Private identifiers are only available when targeting ECMAScript 2015 and higher.
Broken Code ❌
export class MyConverter {
#flatten: (numbers?: (number | number[])[]) => number[];
constructor() {
this.#flatten = (numbers) => {
// Implementation of the flatten function
return [];
};
}
}Solution:
This TypeScript error occurs because private identifiers (#) are a feature introduced in ECMAScript 2015 (ES6) and later. To use private identifiers, you need to ensure that your TypeScript configuration targets at least ES6.
Fixed Code ✔️
{
"compilerOptions": {
"target": "ES6",
"module": "commonjs",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
},
"include": ["src/**/*"],
"exclude": ["coverage", "dist", "node_modules"]
}