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

fix: ensure the typescript definitions only export correct value types #28712

Merged
merged 6 commits into from Jun 15, 2021

Conversation

MarshallOfSound
Copy link
Member

@MarshallOfSound MarshallOfSound commented Apr 18, 2021

In typescript there are two main types of "types" you can export, value types (class, const) and definition types (type, interface). The typescript compiler will let anything declared via const or class be used as a value. Unfortunately we were exporting a bunch of things (see the diff) as class/const when they weren't actually exported values. This lead to typescript being happy but the runtime throwing errors (not something we want).

This change passes "exported-in" context through our docs, to the parser and then to the definitions generator to ensure we only mark things as exported in the ts defs that we actually export.

Fixes #22167

This PR is currently targeting update-ts-parser as it relies on some of those changes and this shows the actual diff.

I've marked this as semver/patch but out of an abundance of caution this shouldn't be backported

Notes: Fixed typescript export definitions such that not-exported values are not declared in the exports interface

@electron-cation electron-cation bot added the new-pr 🌱 PR opened in the last 24 hours label Apr 18, 2021
@MarshallOfSound MarshallOfSound added the semver/patch backwards-compatible bug fixes label Apr 18, 2021
@electron-cation electron-cation bot removed the new-pr 🌱 PR opened in the last 24 hours label Apr 19, 2021
Base automatically changed from update-ts-parser to master April 19, 2021 18:45
Copy link
Member

@nornagon nornagon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think "Exported in" is more confusing than "Process". Can we keep the previous verbiage?

@MarshallOfSound
Copy link
Member Author

@nornagon We have to distinguish between a module being "available" in a process and a module being "exported" in the electron module in that process. If you have an alternative proposal for the words to use to distinguish that I'm open to suggestions, but we can't use the same verbiage in both cases.

MarshallOfSound and others added 4 commits June 14, 2021 10:29
In typescript there are two main types of "types" you can export, value types (class, const) and definition types (type, interface).  The typescript compiler will let anything declared via const or class be used as a value.  Unfortunately we were exporting a bunch of things (see the diff) as class/const when they weren't actually exported values. This lead to typescript being happy but the runtime throwing errors (not something we want).

This change passes "exported-in" context through our docs, to the parser and then to the definitions generator to ensure we only mark things as exported in the ts defs that we actually export.

Fixes #22167
@MarshallOfSound MarshallOfSound force-pushed the fix-exported-values branch 3 times, most recently from 91a5cf9 to dcd479a Compare June 14, 2021 17:35
@MarshallOfSound MarshallOfSound merged commit 8179574 into main Jun 15, 2021
@MarshallOfSound MarshallOfSound deleted the fix-exported-values branch June 15, 2021 20:50
@release-clerk
Copy link

release-clerk bot commented Jun 15, 2021

Release Notes Persisted

Fixed typescript export definitions such that not-exported values are not declared in the exports interface

BlackHole1 pushed a commit to BlackHole1/electron that referenced this pull request Aug 30, 2021
electron#28712)

* fix: ensure the typescript definitions only export correct value types

In typescript there are two main types of "types" you can export, value types (class, const) and definition types (type, interface).  The typescript compiler will let anything declared via const or class be used as a value.  Unfortunately we were exporting a bunch of things (see the diff) as class/const when they weren't actually exported values. This lead to typescript being happy but the runtime throwing errors (not something we want).

This change passes "exported-in" context through our docs, to the parser and then to the definitions generator to ensure we only mark things as exported in the ts defs that we actually export.

Fixes electron#22167

* chore: update typescript-defs

* chore: update typescript-defs

* chore: fix bad typescript in IPC test

* docs: test rendering of new syntax

* chore: update per feedback, use same syntax but with 'this is not exportedd' line
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-backport semver/patch backwards-compatible bug fixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TS definitions of NativeImage static methods are incorrect
2 participants