Skip to content
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

checkJs doesn't detect types of object keys passed to a function #15700

Closed
francescoinfante opened this issue May 9, 2017 · 1 comment
Closed
Labels
Duplicate An existing issue was already created

Comments

@francescoinfante
Copy link

francescoinfante commented May 9, 2017

TypeScript Version: 2.3.2

Code

{
  "compilerOptions": {
    "target": "es6",
    "module": "commonjs",
    "allowJs": true,
    "checkJs": true,
    "noEmit": true
  },
  "include": [
    "./test.js"
  ]
}
/**
 * @param {string} a
 */
function example1(a) {
  a === 2; // error TS2365: Operator '===' cannot be applied to types 'string' and 'number'.
}

/**
 * @param {any} a
 * @param {string} a.b
 */
function example3(a) {
  a.b === 2; // no errors
}

/**
 * @param {{b: string}} a
 * @param {string} a.b
 */
function example5(a) {
  a.b === 2; // error TS2365: Operator '===' cannot be applied to types 'string' and 'number'.
}

/**
 * @param {{b: string}} a
 * @param {number} a.b
 */
function example6(a) {
  a.b === 2; // error TS2365: Operator '===' cannot be applied to types 'string' and 'number'.
}

/**
 * @param {number} a.b
 */
function example7(a) {
  a.b === 2; // error TS2339: Property 'b' does not exist on type 'number'.
}

Expected behavior:

Example 1 works correctly
I expect in example 3 that a.b is detected as a string and that error TS2365 is shown
Example 5 works correctly
I expect in example 6 to say that it's ambiguous.
I expect in example 7 that a is detected as an object and not as a number.

Actual behavior:
Errors shown in the code

@mhegazy
Copy link
Contributor

mhegazy commented May 9, 2017

Duplicate of #11597

@mhegazy mhegazy added the Duplicate An existing issue was already created label May 9, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

2 participants