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

jsdoc: defining object format with @typedef then using it with @type doesn't seem to work #15812

Closed
balupton opened this issue May 13, 2017 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@balupton
Copy link

balupton commented May 13, 2017

TypeScript Version: 2.3.2

Code

example repository: https://github.com/balupton/typescript-typedef-object-issue

source/index.js:

'use strict'

/**
 * @typedef {Object.<string, function(*):boolean>} TypeMap
 */

/**
 * Get the type of the value in lowercase
 * @param {*} value
 * @param {TypeMap} [customTypeMap] a custom type map
 * @returns {?string}
 */
function getType (value, customTypeMap) {
   // Cycle through our type map
   for (const key in customTypeMap) {
      if (customTypeMap.hasOwnProperty(key)) {
         if (customTypeMap[key](value)) {
            return key
         }
      }
   }

   // No type was successful
   return null
}

/**
 * Get the type of the value in lowercase
 * @param {*} value
 * @param {Object.<string, function(*):boolean>} [customTypeMap] a custom type map
 * @returns {?string}
 */
function getTypeWorkaround (value, customTypeMap) {
   // Cycle through our type map
   for (const key in customTypeMap) {
      if (customTypeMap.hasOwnProperty(key)) {
         if (customTypeMap[key](value)) {
            return key
         }
      }
   }

   // No type was successful
   return null
}

tsconfig.json:

{
   "include": [
      "source/*"
   ],
   "compileOnSave": true,
   "compilerOptions": {
      "allowJs": true,
      "checkJs": true,
      "strict": true,
      "alwaysStrict": true,
      "module": "commonjs",
      "newLine": "LF",
      "target": "es2015",
      "outDir": "es2015",
      "lib": [
         "esnext"
      ],
      "rootDir": ".",
      "rootDirs": [
         "."
      ]
   }
}

Expected behavior:
Expected that getType would use the TypeMap type definition correctly.

Actual behavior:
I get this error message on compile:

> tsc

source/index.js(17,14): error TS7017: Element implicitly has an 'any' type because type '{}' has no index signature.

VSCode Screenshots:

img_4826

img_4827

@mhegazy
Copy link
Contributor

mhegazy commented May 20, 2017

looks like a duplicate of #15105

@mhegazy mhegazy added the Duplicate An existing issue was already created label May 20, 2017
@mhegazy
Copy link
Contributor

mhegazy commented Jun 4, 2017

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

@mhegazy mhegazy closed this as completed Jun 4, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
This issue was closed.
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