Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve exported types definition for v2 to include Parser namespace #285

Closed
mradcliffe opened this issue Jan 22, 2019 · 5 comments
Closed
Labels
question Question about the project or any related thing

Comments

@mradcliffe
Copy link

This is a follow-up from #272.

I tried out the typings is 2.0.0, but it seems like the typings aren't usable except for a very limited use case. Typescript version 3.2.2 reported in Visual Studio Code.

For instance, I can do the following:

import { parse } from 'bowser';

// browser.os.name autocompletes here in Code.
const browser = parse(window.navigator.userAgent);

but I cannot type the variables themselves:

// Errors out because Parser.ParsedDetail is not available.
const browser: Parser.ParsedDetail = parse(window.navigator.userAgent);

This may not seem important in that example, but it is important in a class context:

class Blah {
  // This cannot be assigned a type because Parser is not available as an export.
  // Leaving it as "any" means that no type completion is available in a IDE so a
  // developer has to memorize the API.
  browser: Parser.ParsedDetail;

  constructor() {
    this.browser = parse(window.navigator.userAgent);
  }
}

Basically anything other than getParser and parse cannot be used as types. This seems to correspond to comment in #277:

I think and I've tried 😂 this should be the stable version, but the only thing I don't know yet is if through these typings, users could maybe access to Parser as definition even if they cannot in real. I have to test this aspect.

I tried hacking in export as namespace Parser;, but I couldn't import it. I'm not really good at creating typings so I had to take all the Parser namespace and paste it into my typings.d.ts file to workaround this.

@lancedikson
Copy link
Collaborator

Hi, @mradcliffe. I'm not that good at typings either to answer correctly, but I'm diving into TypeScript nowadays, so, I hope, I'll be able to improve it exporting all the needed types :)

@lancedikson lancedikson added the question Question about the project or any related thing label Jan 24, 2019
@lancedikson
Copy link
Collaborator

lancedikson commented Jan 25, 2019

Ok, now I see the problem. We don't export those auxiliary types from the typing declaration file. So, it seems that we can do that. And, actually, namespaces seem a bit useless. I'll try to review the typings this weekend and hopefully come up with a bulletproof solution.

@JaceHensley
Copy link
Contributor

@lancedikson I'm gonna put a PR shortly to do this

@JaceHensley
Copy link
Contributor

#289

@lancedikson
Copy link
Collaborator

Forgot to close this one after merging the PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question about the project or any related thing
Projects
None yet
Development

No branches or pull requests

3 participants