Here is a code example
export default class Entity {
#id
#tag
#alive = true
constructor(tag = "default", id = 0) {
this.#tag = tag
this.id = id
}
}
If this code is in a file with a .ts
extension I get the following error on the this.id = id
, assignment:Property 'id' does not exist on type 'Entity'.ts(2339)
If I turn this file into a .js
extension I no longer get this error ONLY if I do not assign it, in my jsconfig.json
I have tried the following:
{
"compilerOptions": {
"module": "ESNext",
"target": "ESNext",
"checkJs": true,
// Strict Checks
"strictPropertyInitialization": true,
"alwaysStrict": true, // Ensures that your files are parsed in the ECMAScript strict mode, and emit “use strict” for each source file.
"allowUnreachableCode": false, // pick up dead code paths
"noImplicitAny": true, // In some cases where no type annotations are present, TypeScript will fall back to a type of any for a variable when it cannot infer the type.
"strictNullChecks": true, // When strictNullChecks is true, null and undefined have their own distinct types and you’ll get a type error if you try to use them where a concrete value is expected.
// Linter Checks
"noImplicitReturns": true,
"noUncheckedIndexedAccess": true, // accessing index must always check for undefined
"noUnusedLocals": true, // Report errors on unused local variables.
"noUnusedParameters": true // Report errors on unused parameters in functions
}
}
I want to achieve the same behavior using a .js
as with the .ts
1