I am attempting to interact with a REST api using jQuery's ajax
feature.
My goal is to return the Promise<Customer>
object, but I am encountering an error stating that the property finally
is missing. It used to work before, so I assume there have been some recent changes. However, I am struggling to figure out how to include the missing finally
property.
I believe there must be a simple solution, but unfortunately, I haven't been able to find a fix online.
The issue is within the following class:
export class ServiceCustomer {
public requestCustomers(): Promise<Customer> {
const dataString: ResourceParamCustomer = {
something: 'some entry',
nextthing: 'other entry',
};
return $.ajax({
contentType: 'application/json',
data: JSON.stringify(dataString),
dataType: 'json',
type: 'POST',
url: 'http://localhost:3000/api/customer/list',
});
}
}
The error message received:
ERROR in [at-loader] ./src/Service/ServiceCustomer.ts:12:15
TS2741: Property 'finally' is missing in type 'jqXHR<any>' but required in type 'Promise<Customer>'.
Key information from the package.json
:
{
...
"dependencies": {
...
"@types/jquery": "3.3.31",
...
"jquery": "3.4.1",
"popper.js": "1.16.0",
...
},
"devDependencies": {
"autoprefixer": "9.7.1",
"awesome-typescript-loader": "5.2.1",
"clean-webpack-plugin": "3.0.0",
...
"html-webpack-plugin": "3.2.0",
...
"tslint": "5.20.1",
"typescript": "3.7.2",
"typings-for-css-modules-loader": "1.7.0",
...
},
...
}
The tsconfig.json configuration:
{
"compilerOptions": {
"outDir": "./dist/",
"sourceMap": true,
"noImplicitAny": true,
"module": "commonjs",
"target": "es2015",
"jsx": "react",
},
"include": [
"./src/**/*"
]
}