On a number of occasions, I have been burned by some Typescript behaviour that I'd like to disable.
I recently realized that a library I was using had a peer dependency on @types/bluebird
for its Promise type.
I had not installed this dependency. A consequence of this was that any method from that library that returned a bluebird Promise
, the inferred return type in my code was any
. For example:
// Library .d.ts file
import * as Bluebird from 'bluebird';
const Promise: typeof Bluebird;
export const libraryFunction = () => Promise.resolve(42);
// My code .ts file
// Should be () => Promise<number>
// is actually () => any
const yUNoWorkRight = async () => libraryFunction();
Is there a setting that would cause this to fail or, at least, get caught by tslint
?
noImplicitAny
does not seem to help here.
Here's my TS config:
{
"compilerOptions": {
"allowJs": true,
"allowSyntheticDefaultImports": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"inlineSources": true,
"jsx": "react",
"lib": [
"dom","es2018", "esnext"
],
"module": "commonjs",
"noImplicitAny": true,
"noImplicitThis": true,
"noImplicitReturns": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"moduleResolution": "node",
"outDir": "./built",
"preserveConstEnums": true,
"resolveJsonModule": true,
"sourceMap": true,
"strict": true,
"strictNullChecks": true,
"target": "es2018",
"types": ["mocha", "node"],
"sourceRoot": "/"
},
"include": [
"src/**/*.ts", "src/**/*.js", "test/**/*.ts", "test/**/*.js"
]
}
and TSLint
{
"linterOptions": {
"exclude": [
"**/*.json"
]
},
"rules": {
"adjacent-overload-signatures": true,
"prefer-for-of": true,
"unified-signatures": true,
"no-any": true,
"label-position": true,
"no-arg": true,
"no-construct": true,
"no-invalid-this": true,
"no-misused-new": true,
"no-shadowed-variable": true,
"no-string-throw": true,
"no-var-keyword": true,
"strict-boolean-expressions": [
true,
"ignore-rhs"
],
"triple-equals": [
true,
"allow-null-check",
"allow-undefined-check"
]
},
"jsRules": {
"object-literal-sort-keys": false,
"no-console": false,
"quotemark": false,
"trailing-comma": false,
"no-empty": [
true,
"allow-empty-functions"
]
}
}