Skip to content

first draft of typings for typescript #69#71

Merged
amitguptagwl merged 2 commits intoNaturalIntelligence:masterfrom
bb:master
Apr 2, 2018
Merged

first draft of typings for typescript #69#71
amitguptagwl merged 2 commits intoNaturalIntelligence:masterfrom
bb:master

Conversation

@bb
Copy link
Contributor

@bb bb commented Mar 31, 2018

Purpose / Goal

Some type definitions for external API, attempt to fix #69.

This PR doesn't change anything at runtime, it's only typing support for users use typescript.

It's not yet complete, but it is a start and better than nothing.

A different approach to create a separate typings file would be to convert the whole project to typescript. That would be a pretty big step and would also influence further development workflow, build process etc.

Outlook

Besides filling the gaps of this type definitions, it might be interesting to provide a second signature to parse which takes a generic type. This could then be used as the return value.
Thus, when the developer knows that the parsed XML will be in a certain structure,
It might look something like this, but I didn't try it:

export function parse(xmlData: string, options?: X2jOptionsOptional): any;
export function parse<T>(xmlData: string, options?: X2jOptionsOptional): T;

Usage would then be parse<Whatever>(myXmlData). In this case, Typescript would know that the output is of type Whatever instead of any. Without this extra definition, a similar result can be achieved with parse(myXmlData) as Whatever. Neither of those has any runtime impact, it's just at development time. I'm not sure if it is good practice, so I left it out for now.

Type

[ ]Bug Fix
[ ]Refactoring / Technology upgrade
[x]New Feature

@coveralls
Copy link

coveralls commented Mar 31, 2018

Coverage Status

Coverage remained the same at 97.543% when pulling 4dbd87f on bb:master into 04fe450 on NaturalIntelligence:master.

@amitguptagwl amitguptagwl merged commit 273416b into NaturalIntelligence:master Apr 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: TypeScript type definitions

3 participants