When I import 'datatables.net-buttons' in a Angular Typescript project it breaks my code.
When I import 'datatables.net-buttons' in a Angular Typescript project it breaks my code.
laucha54321
Posts: 3Questions: 1Answers: 0
Error: node_modules/datatables.net-buttons/types/types.d.ts:55:4 - error TS7013: Construct signature, which lacks return-type annotation, implicitly has an 'any' return type.
55 new (dt: Api<any>, settings: boolean | ConfigButtons | Array<string | ButtonConfig>);
This is the error that gets shown.
I use this import syntax:
import 'datatables.net-buttons';
Answers
I've just made the connection between this thread and the GH pull request you sent. The PR makes more sense now!
However, Typescript should make that inference automatically. What version of Typescript are you using please?
Allan
I am using version 5.0.4 of Typescript.
@allan
Sorry I wasn't able to reply this afternoon (no bump required, sometimes I just can't reply to threads within two hours - indeed I'm out tomorrow for a funeral so probably won't be on).
The TypeScript documentation says:
Perhaps I'm missing something, but
new
is a constructor so adding a return type isn't needed and indeed would be wrong.any
would certainly not be right since it isn't returning anany
. If it needs to be typed it would be returning aDataTable.Buttons
instance.I'll try testing it as soon as I can. Probably on Wednesday.
Allan
While looking into this I realised that the Buttons object was being attached to the wrong DataTables host object. I've corrected that now and something like this will work in Typescript happily now:
Before it gave an error about
Buttons
not being defined on theDataTable
object.I don't think that will fix the error you are seeing though, as I still don't know what is causing that. If you can use codesandbox.io or something to create an example showing the issue that would be really useful.
Allan