Skip to content
This repository was archived by the owner on Apr 18, 2023. It is now read-only.

Typescript #39

Merged
merged 31 commits into from
Oct 1, 2018
Merged

Typescript #39

merged 31 commits into from
Oct 1, 2018

Conversation

keanulee
Copy link
Contributor

@keanulee keanulee commented Sep 26, 2018

Most of the code was previously reviewed in un-merged PR #24. Published the contents of this branch as 0.8.4-pre.1/@next to NPM for testing apps that use this library.

cc @rictic @aomarks for feedback on TS-specific things

Fixes #37

Copy link

@rictic rictic left a comment

Choose a reason for hiding this comment

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

A few small TypeScript suggestions. Otherwise LGTM

this._clicksSpan = shadowRoot.getElementById('clicksSpan');
this._valueSpan = shadowRoot.getElementById('valueSpan');
this._didLoadSpan = shadowRoot.getElementById('didLoadSpan');
this._counter = shadowRoot.querySelector('counter-element')! as CounterElement;
Copy link

Choose a reason for hiding this comment

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

Instead of this cast, can extend the HTMLElementTagNameMap in counter-element

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed the extension in 96251f0 because this extension (which is intended for the demo in this repo only) was adding 'counter-element' to the generated typings in connect-mixin.d.ts:

export declare const connect: /*...*/(baseElement: T) => {
  new (...args: any[]): {
    /*...*/
    querySelector<K extends "object" | "font" | /*...*/ | "xmp" | "counter-element">(selectors: K): HTMLElementTagNameMap[K] | null;
    /*...*/
  };
} & T;
export {};

which is consumed by apps using this library which may not have a counter-element and causes a TS compile error for the app:

../pwa-helpers/connect-mixin.d.ts:156:1260 - error TS2536: Type 'K' cannot be used to index type 'HTMLElementTagNameMap'.

Ideally there's a way to remove this typing, but I think this is just how TS creates typings for mixin functions.

Copy link

Choose a reason for hiding this comment

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

Oh I see, I missed that this was in the demo subdirectory.

Copy link

Choose a reason for hiding this comment

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

Also, ouch on that typings expansion. That looks like it's related to microsoft/TypeScript#27171

@@ -0,0 +1,12 @@
interface Event {
composedPath(): EventTarget[];
Copy link

Choose a reason for hiding this comment

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

I think as of TypeScript 3.0 this type is in the built-in typings

Copy link
Contributor Author

Choose a reason for hiding this comment

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

EventInit.composed was available, but not composedPath():

src/router.ts:52:22 - error TS2339: Property 'composedPath' does not exist on type 'MouseEvent'.

52     const anchor = e.composedPath().filter(
                        ~~~~~~~~~~~~

Copy link
Member

Choose a reason for hiding this comment

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

Yeah composedPath() is not in the current 3.0 release yet, but should be in the next one.
microsoft/TypeScript-DOM-lib-generator#523

}

interface EventInit {
composed?: boolean;
Copy link

Choose a reason for hiding this comment

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

This too

() => this._loadReducer());
}

_stateChanged(state) {
_stateChanged(state: AppState) {
const numClicks = this._counter .clicks = state.counter.clicks;
Copy link
Member

Choose a reason for hiding this comment

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

Remove the space between this._counter and .click.

);

const reducer: ReducersMapObject<AppStateCounter, CounterAction> = { counter };
store.addReducers(reducer);
Copy link
Member

Choose a reason for hiding this comment

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

I think you can just do store.addReducers({ counter }); and remove const reducer: ...

@@ -0,0 +1,38 @@
import { installRouter } from '../router.js';
Copy link
Member

Choose a reason for hiding this comment

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

Add license

@keanulee
Copy link
Contributor Author

Published the contents of this branch as 0.8.4-pre.1/@next to NPM for testing apps that use this library.

@keanulee keanulee merged commit bc756a9 into master Oct 1, 2018
@keanulee keanulee deleted the typescript branch October 1, 2018 23:08
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants