Skip to content

In JS, assignment to an undeclared instance property should act as its declaration #22896

@mohsen1

Description

@mohsen1

TypeScript Version: 2.7.0-dev.201xxxxx

Search Terms:
Salsa, Class member, instance

TypeScript Version
2.7.2

Code

// tsconfig
{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "allowJs": true,
    "checkJs": true,
    "outDir": "./dist",
    "strict": true,
    "esModuleInterop": true
  }
}
// index.js
class Foo {};
let f = new Foo();
f.bar = 1

Expected behavior:
No error

Actual behavior:

$ tsc --pretty
index.js:3:3 - error TS2339: Property 'bar' does not exist on type 'Foo'.

3 f.bar = 1
    ~~~

Metadata

Metadata

Assignees

No one assigned

    Labels

    Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureDomain: JavaScriptThe issue relates to JavaScript specificallySuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions