Typescript interfaces exported vs not
Typescript interfaces exported vs not
Looking at the source code I see the DataTableDom interface, and it looks like it should be exported. But it's not exported in the built file. Is this expected? Is there a reason not to export everything?
Answers
Hi,
The primarily reason for there being only selected interfaces exported is future backwards compatibility. I don't want to export everything and then be bound by the implicit API contract that makes (my naming consistency for interfaces is fairly poor for example - I'd like to find some time to sort it out at some point, and have the option of cleaning them up in future).
Any function that uses
DataTableDomshould allow implicit types (unless you are creating a named function and assigning it?). Can you show me a use case for it perhaps please?Thanks,
Allan
Ok I left an answer but after editing it three times it vanished lol Trying again...
We use a custom object to set up the DataTable that will be drawn on each page. I like to have IDE autocompletion so I made an interface for it, but wasn't able to specify the
thiscontext for the callback functions. I ended up making my ownDataTableDomsince it's only three lines, but there are other more complicated interfaces likeConfigColumnDefsthat would be helpful to have available. e.g.:I don't know if this is a common use pattern or not? I've only been using TS for about a year now and my background is in PHP and JavaScript where we don't have this disconnect between the source and the end product. I may be abusing TS to fit into my notions of how a language "should" behave.
The spam queue caught it. I've marked your account so that shouldn't happen again.
Yes I see. I wonder if extending the
Optionstype that you can get fromdatatables.netwould do the job here:Then you get all the types and options automatically inherited:
Allan
Well it currently only has a subset of the options, but yeah maybe it's easier to just account for the additional options and do it that way.
TypeScript has got you covered there as well. You don't need to just extend from
Options, but rather you can usePickorOmitto selectively include or exclude properties from another interface.So if you want to present only specific properties from
Optionsyou could usePickand extend from that, while retaining all the typing of the DataTables exportedOptionsinterface.Allan