If we try the example given in documentation page Non-standard request / response format in a TypeScript file, we get a TS2339 error:
// Example found in https://github.com/tkirda/jQuery-Autocomplete#non-standard-request--response-format
/// <reference path="../node_modules/devbridge-autocomplete/dist/jquery-plugin.d.ts" />
$('#autocomplete').autocomplete({
paramName: 'searchString',
transformResult: function (response ) {
return {
suggestions: response.myData.map((item) => ({ // ⚠️TS2339 - Property 'myData' does not exist on type 'string | AutocompleteResponse'. Property 'myData' does not exist on type 'string'.
value: item.valueField,
data: item.dataField,
})),
};
},
});
What happened
TypeScript compiler report an error TS2339:
Property 'myData' does not exist on type 'string | AutocompleteResponse'.
Property 'myData' does not exist on type 'string'.
What you expected to happen
TypeScript compiler should accept any type for argument response. Definition of response type in TransformResult is too restrictive.
Versions
devbridge-autocomplete: 2.0.4
jquery: 3.7.1
- Browser + OS: all
Autocomplete options
$('#autocomplete').devbridgeAutocomplete({
paramName: 'searchString',
transformResult: function (response ) {
return {
suggestions: response.myData.map((item) => ({
value: item.valueField,
data: item.dataField,
})),
};
},
});
Steps to reproduce
- Copy the example given in documentation page Non-standard request / response format in a TypeScript file
- Try compiling this TypeScript file
- See compiler error
If we try the example given in documentation page Non-standard request / response format in a TypeScript file, we get a
TS2339error:What happened
TypeScript compiler report an error
TS2339:What you expected to happen
TypeScript compiler should accept any type for argument
response. Definition ofresponsetype inTransformResultis too restrictive.Versions
devbridge-autocomplete: 2.0.4jquery: 3.7.1Autocomplete options
Steps to reproduce