Skip to content

Accessing nonexistent properties is not checked in JS files #22288

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

Closed
que-etc opened this issue Mar 2, 2018 · 3 comments
Closed

Accessing nonexistent properties is not checked in JS files #22288

que-etc opened this issue Mar 2, 2018 · 3 comments
Labels
Design Limitation Constraints of the existing architecture prevent this from being fixed

Comments

@que-etc
Copy link

que-etc commented Mar 2, 2018

TypeScript Version: 2.8.0-dev.20180302

Search Terms:

  • checkJs
  • noImplicitAny
  • object
  • undefined

Code

const fruits = {
    PINEAPPLE: 'tasty'
};

// Name of the property is mistyped and running this code in JS engines
// will result in a TypeError.
fruits.PINAPPLE.toUpperCase();

Expected behavior:
Following error should be raised if checkJs and noImplicitAny flags are enabled:
Property 'PINAPPLE' does not exist on type '{ PINEAPPLE: string; }'. Did you mean 'PINEAPPLE'?

Actual behavior:
No error is shown.

Related Issues: #16137 - this one describes a similar problem, but for some reason it was closed by reporter.

@ghost ghost added the Bug A bug in TypeScript label Mar 2, 2018
@ghost
Copy link

ghost commented Mar 2, 2018

Probably a bug in the code that allows JS objects created by object literals to be assigned new properties -- but a property access should still be an error.

@mhegazy mhegazy added Design Limitation Constraints of the existing architecture prevent this from being fixed and removed Bug A bug in TypeScript labels Mar 2, 2018
@mhegazy
Copy link
Contributor

mhegazy commented Mar 2, 2018

Objects in a .js file are assumed to be open-ended. in other words they behave as if they had { [x:string]: any; } on them.

@typescript-bot
Copy link
Collaborator

Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

@microsoft microsoft locked and limited conversation to collaborators Jul 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Design Limitation Constraints of the existing architecture prevent this from being fixed
Projects
None yet
Development

No branches or pull requests

3 participants