I'm using Axios to handle some API fetching, and I'm executing that call within a generator; async/await
is not an option for this particular project. For some reason, even though axios
is getting my types right, typescript is inferring an any
type when I use the yield
keyword.
function* foo() {
// axios.get is returning Promise<AxiosResponse<T>>
// but data is being inferred as "any"
const { data } = yield axios.get<T>(url);
// do some stuff with data
}
If I specfically type the axios response, it works fine, but I feel like I'm missing something, since TS isn't getting the type automatically
function* foo() {
const { data }: AxiosResponse<T> = yield axios.get<T>(url);
// do some stuff with data
}
Is there some other step or config I'm missing?
Here's my tsconfig
{
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/",
"sourceMap": true,
"noImplicitAny": false,
"module": "commonjs",
"target": "es6",
"jsx": "react",
"removeComments": true,
"allowJs": true,
"skipLibCheck": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"rootDirs": ["src", "src/stories"],
"paths": {
"*": ["./src/custom-types/*"]
},
"types": ["@emotion/core", "jest"]
},
"include": ["./src/**/*"]
}