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

misc(tsc): reorganize and expose external interfaces #4788

Merged
merged 3 commits into from
Mar 16, 2018
Merged

Conversation

brendankenny
Copy link
Member

@brendankenny brendankenny commented Mar 16, 2018

moves public interfaces of Audit and Gatherer to audit.d.ts and gatherer.d.ts. This fixes the problem that typedefs on a class (e.g. Audit) are only local and aren't actually exposed on that module when required elsewhere.

Also changes the product of Audit.audit() to LH.Audit.Product from LH.AuditResult, which allows LH.AuditFullResult (which is actually in the LHR) to just be LH.Audit.Result. Happy to bikeshed on these, though :)

Also update to typescript 2.8 (rc) because there's a bug in 2.7 when it wasn't actually checking optional properties when in JS files (not using any new features yet). Can move over to 2.8 when it hits release very soon.

* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/

declare namespace LH.Audit {
Copy link
Member Author

Choose a reason for hiding this comment

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

global namespaces are merged, so this adds to the LH namespace defined in externs.d.ts

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.

glad to start getting some structure in our typings! 🎉

*/

declare namespace LH.Audit {
export interface ScoringModes {
Copy link
Collaborator

Choose a reason for hiding this comment

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

enum?

Copy link
Member Author

Choose a reason for hiding this comment

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

it looks like we can't (at least in a d.ts file). Since enum defines a type and a value in ts, it expects you to use the value of the enum anywhere the type is expected. So e.g. the values of Audit.SCORING_MODES would have to be LH.Audit.ScoringModes (not just 'numeric' and 'binary', even though that's what those are), but those don't exist in JS if the enum is defined here.

Copy link
Member Author

Choose a reason for hiding this comment

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

I could be wrong, but I can't make it work. Playground example

Copy link
Collaborator

Choose a reason for hiding this comment

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

you mean you're not a fan of this!?

😆

// TODO: placeholder typedefs until Details are typed
export interface DetailsRendererDetailsSummary {
wastedMs?: number;
wastedKb?: number;
Copy link
Collaborator

Choose a reason for hiding this comment

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

carryover but this is wastedBytes :)

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@vinamratasingal-zz
Copy link

I'll let Paul and Patrick take this review, no opinion from my side.

@paulirish paulirish merged commit 8d64c26 into master Mar 16, 2018
@paulirish paulirish deleted the tsfixup branch March 16, 2018 23:04
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.

None yet

5 participants