Closed
Description
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: