'Setting for more strict validation on interface methods
We are running a monorepo and have contracts with one interface of methods that takes a request and returns a Promise<Response>
. One interface example is such:
interface MyApi {
getUsers(args: GetUsersRequest): Promise<GetUsersResponse>;
}
When we implement this, we want TypeScript to not build/compile and give an error if this contract is not met. However this passed the build, so I am wondering if there is a setting I am missing that I can add:
class MyController implements MyApi {
getUsers(@Body() body: GetUsersRequest): Promise<any> {
return new Promise((res, rej) => {
res(1);
});
}
}
This method should be forced to return Promise<GetUsersResponse>
per the contract.
tsconfig.json
:
{
"compilerOptions": {
"module": "commonjs",
"declaration": true,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"target": "es2017",
"sourceMap": true,
"outDir": "./dist",
"baseUrl": "./",
"incremental": true,
"skipLibCheck": true,
"strictNullChecks": false,
"noImplicitAny": false,
"strictBindCallApply": false,
"forceConsistentCasingInFileNames": false,
"noFallthroughCasesInSwitch": false,
"typeRoots": ["./types"],
"types": ["@types/jest", "node"],
"rootDir": "./"
},
"modulePaths": ["<rootDir>"]
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|