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

TS: New typings inferior to former @types ones #3878

Closed
SimonSchick opened this issue Feb 1, 2019 · 11 comments
Closed

TS: New typings inferior to former @types ones #3878

SimonSchick opened this issue Feb 1, 2019 · 11 comments
Labels

Comments

@SimonSchick
Copy link

SimonSchick commented Feb 1, 2019

Steps to reproduce

Tell us about your environment:

  • Puppeteer version: 1.12
  • Platform / OS version: Irrelevant
  • URLs (if applicable):
  • Node.js version: Irrelevant

What steps will reproduce the problem?

Please include code that reproduces the issue.

Update puppeteer
2.
Check typings.
3.
They are worse.

What is the expected result?

Typings should be at least at DT quality.

What happens instead?

  • Various types have become Function
    • Callbacks in waitFor/evaluate-ish functions.
  • Various types have come Object
    • Often incorrect such as jsonValue or json (should be 'unknown' instead)
    • Used instead of more precise dictonary object when used for headers and waitFor options.
  • Various specific overloads are missing that make requires less type assertions.

Both types should not be used as they are extremely broad.

FYI I consider this a breaking change as I cannot easily revert to DT typings without explicitly downgrading puppeteer, it also broke our builds.

aslushnikov pushed a commit that referenced this issue Feb 1, 2019
It looks like this was a breaking change for people using DefinitelyTyped's definitions. Let's revert, and revisit it for 2.0

References #3878, #2079
@aslushnikov
Copy link
Contributor

@SimonSchick thank you for letting us know and sorry for breaking you. We'll push a 1.12.1 without d.ts file shortly

@SimonSchick
Copy link
Author

Obviously: I really appreciate you adding those, it's great they we don't need to maintain them separately anymore, but they need some fine tuning :)

Also worth noting is that typings for

image

would also be nice :)

@SimonSchick
Copy link
Author

You might want to include https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/puppeteer/puppeteer-tests.ts as some sort of test baseline.

@JoelEinbinder
Copy link
Collaborator

They are included and all passed at at https://github.com/GoogleChrome/puppeteer/blob/master/utils/doclint/generate_types/test/test.ts

Seems like there is some untested functionality though. If you could sending a PR adding failing code to that file (just leave it commented out) it would be super helpful!

@SimonSchick
Copy link
Author

Ah yea, I didn't see it there, and yea the tests are far from complete, I will see if I get around to it.

aslushnikov added a commit that referenced this issue Feb 1, 2019
@aslushnikov
Copy link
Contributor

1.12.1 is out now with removed index.d.ts file. I'll keep this issue open to track progress on making our generated index.d.ts better and maybe eventually ship them again.

@SimonSchick
Copy link
Author

See DefinitelyTyped/DefinitelyTyped#32723, I added a few extra tests, should help you a bit.

Also, it seems your generated generated some interfaces multiple times, see PageMetricsPayload

yhatt added a commit to marp-team/marp-cli that referenced this issue Feb 2, 2019
Puppeteer v1.12.0 had added the official type definition, but updated
v1.12.1 has removed it because of low quality.

See: puppeteer/puppeteer#3878
yhatt added a commit to marp-team/marp-cli that referenced this issue Feb 2, 2019
* Upgrade dependent packages to latest

* Revert deletion of @types/puppeteer in 302d5f6

Puppeteer v1.12.0 had added the official type definition, but updated
v1.12.1 has removed it because of low quality.

See: puppeteer/puppeteer#3878

* Upgrade Node to v10.15.1

* Fix TS compile error caused by returning unused value

* Fix TypedEventEmitterr to use compatible lister function type

* Test with Node 8.9, the least required version

* Use independent Chrome instance per example while testing Converter

* Revert test with Node 8.9

* Update CHANGELOG.md
@SimonSchick
Copy link
Author

Going to be devils advocate: at this point I think it would be easiest to just port puppeteer to TS than invest further work into the types generator for adding overloads and such.

In the end every contributor needs to know TS to write the doctags anyways.

@JoelEinbinder
Copy link
Collaborator

I don't see how switching to TypeScript helps to solve any of these problems. TypeScript's generated d.ts file is not going to be higher quality than the one I'm generating.

@SimonSchick
Copy link
Author

SimonSchick commented Feb 4, 2019

@JoelEinbinder the main pain point I see here will be specifying overloads for waitFor, especially for conditional return types.

I've tried to find out how to specify those via JSDoc but haven't found a way to make this work.

@pocesar
Copy link

pocesar commented Aug 11, 2019

weak typings generates errors in builds, that's the whole point of the compiler barking at your loose code. if puppeteer code doesn't account for strict parameters, it will indeed generate just-as-weak typings, even if the codebase is converted to TS.
non-generics (any, unknown, never) should be seldomly used in a consumable library with such a big API surface. the point of well-thought-out interfaces is that, if it compiles, it'll most likely work, but being typed, by itself, guarantees nothing (ahem, Java)

@jrandolf jrandolf closed this as completed Jun 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants