I'm developing a personal project using typescript v3.6.4 and twitter API (twit).
I've also installed @types/twit from https://www.npmjs.com/package/@types/twit
I want to make a request to a 'lists/members' endpoint.
My code is:
import Twit from "twit";
const client = new Twit(...);
client.get('lists/members', {list_id: '123123'})
But, typescript gives me an error:
src/data/TwitterProvider.ts:16:34 - error TS2769: No overload matches this call.
Overload 1 of 3, '(path: string, callback: Callback): void', gave the following error.
Argument of type '{ list_id: string; }' is not assignable to parameter of type 'Callback'.
Object literal may only specify known properties, and 'list_id' does not exist in type 'Callback'.
Overload 2 of 3, '(path: string, params?: Params): Promise<PromiseResponse>', gave the following error.
Argument of type '{ list_id: string; }' is not assignable to parameter of type 'Params'.
Object literal may only specify known properties, and 'list_id' does not exist in type 'Params'.
client.get('lists/members', {list_id: 'test'})
Which makes sense, since there's no list_id property in https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/twit/index.d.ts file
I did some research and created ./src/@types/twit.d.ts:
import "twit";
declare module 'twit' {
namespace Twit {
interface Params {
list_id?: string;
}
}
}
However I still get the same error.
My tsconfig.json:
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"moduleResolution": "node",
"outDir": "dist",
"rootDir": "src",
"sourceMap": true
},
"typeRoots": [
"src/@types",
"node_modules/@types"
],
"include": [
"src/**/*.ts"
],
"exclude": [
"node_modules"
]
}
And I'm running the code by ts-node src/index.ts