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

core(tsc): use Config class to define Config type #5525

Merged
merged 1 commit into from
Jun 20, 2018

Conversation

brendankenny
Copy link
Member

Previously there was the Config class (in config.js) and the LH.Config type (in config.d.ts). The LH.Config type implemented LH.Config.Json, ensuring that any LH.Config was also a valid LH.Config.Json.

When passing around an instance of Config we called it an LH.Config, which meant the compiler was enforcing that it implemented both interfaces, but that means two sources of truth for what a "Config" is and indirect errors if those interfaces were violated.

Based on @patrickhulce's idea in #5451 to enforce interfaces until tsc supports @implements tags, we can eliminate the d.ts declaration of LH.Config and just use the Config class directly, just asserting that the object is a valid LH.Config.Json near the end of the constructor in a throwaway variable.

(the rest of the config interfaces staying separate for now because @typedef doesn't support inheritance yet 🙄 and they aren't clearly defined anywhere with a constructor or single object literal)

@@ -303,6 +303,7 @@ const mergeOptionsOfItems = (function(items) {
class Config {
/**
* @constructor
* @implements {LH.Config.Json}
Copy link
Member Author

Choose a reason for hiding this comment

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

non-functional for now

Copy link
Collaborator

@patrickhulce patrickhulce left a comment

Choose a reason for hiding this comment

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

LGTM!

@brendankenny brendankenny merged commit 6bf2f45 into master Jun 20, 2018
@brendankenny brendankenny deleted the implementsconfig branch June 20, 2018 18:24
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.

3 participants