Skip to content
This repository has been archived by the owner on Mar 13, 2020. It is now read-only.

TypeScript template #235

Merged
merged 16 commits into from
Oct 10, 2018
Merged

TypeScript template #235

merged 16 commits into from
Oct 10, 2018

Conversation

keanulee
Copy link
Contributor

@keanulee keanulee commented Sep 27, 2018

PR opened for review comments only - this branch serves as a template on how to use TypeScript.

Fixes #232

@keanulee keanulee requested a review from frankiefu as a code owner September 27, 2018 22:41
Copy link
Member

@frankiefu frankiefu left a comment

Choose a reason for hiding this comment

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

minor comments on typescript stuffs

@@ -48,27 +60,27 @@ const loadPage = (page) => (dispatch) => {
dispatch(updatePage(page));
};

const updatePage = (page) => {
const updatePage: ActionCreator<Action> = (page: string) => {
Copy link
Member

Choose a reason for hiding this comment

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

How about using a more specific type:
const updatePage: ActionCreator<AppActionUpdatePage> = (page: string) => {
or
const updatePage = (page: string): AppActionUpdatePage => {

opened
});
}
export const updateDrawerState: ActionCreator<Action> = (opened: boolean) => {
Copy link
Member

Choose a reason for hiding this comment

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

Use AppActionUpdateDrawerState

export interface CounterActionIncrement extends Action<'INCREMENT'> {};
export interface CounterActionDecrement extends Action<'DECREMENT'> {};
export type CounterAction = CounterActionIncrement | CounterActionDecrement;

export const increment = () => {
Copy link
Member

Choose a reason for hiding this comment

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

Add type CounterActionIncrement, e.g. export const increment = (): CounterActionIncrement => {

dispatch(addToCartUnsafe(productId));
}
};

export const removeFromCart = (productId) => {
export const removeFromCart: ActionCreator<Action> = (productId) => {
Copy link
Member

Choose a reason for hiding this comment

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

<Action> -> <ShopActionRemoveFromCart>

return {
type: REMOVE_FROM_CART,
productId
};
};

export const addToCartUnsafe = (productId) => {
export const addToCartUnsafe: ActionCreator<Action> = (productId) => {
Copy link
Member

Choose a reason for hiding this comment

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

ShopActionAddToCart

@abdonrd
Copy link
Contributor

abdonrd commented Oct 4, 2018

It seems that this template does not work with the new Typescript 3.1.

screenshot 2018-10-05 at 00 30 27

Ignore the .d.ts, .js & .js.map just in src folder
@googlebot
Copy link

So there's good news and bad news.

👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there.

😕 The bad news is that it appears that one or more commits were authored or co-authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that here in the pull request.

Note to project maintainer: This is a terminal state, meaning the cla/google commit status will not change from this state. It's up to you to confirm consent of all the commit author(s), set the cla label to yes (if enabled on your project), and then merge this pull request when appropriate.

@mercmobily
Copy link

So... this is meant to be turned into a "supported" template soon, right?
Is it finished as it is? Or is more testing required?

@keanulee
Copy link
Contributor Author

keanulee commented Oct 5, 2018

It's mostly finished. Currently waiting on:

  • Next pwa-helpers release, where underscore is removed from stateChanged() to match LitElement's convention of no underscore for protected methods (No underscore in connect-mixin API pwa-helpers#43)
  • Next LitElement release, where LitElement is no longer abstract so we don't need to do the "Connected" element subclassing thing

Haven't looked into the TS 3.1 issues - that's probably for another PR. The process of "releasing" this template will probably just be renaming this branch to template-typescript.

@abdonrd
Copy link
Contributor

abdonrd commented Oct 5, 2018

  • Next pwa-helpers release, where underscore is removed from stateChanged() to match LitElement's convention of no underscore for protected methods (Polymer/pwa-helpers#43)

About the underscore, you are also going to eliminate it from the properties?

@keanulee
Copy link
Contributor Author

keanulee commented Oct 5, 2018

@abdonrd no - the convention is no underscore on protected methods

@abdonrd
Copy link
Contributor

abdonrd commented Oct 6, 2018

By the way, any plan to add watch to the npm start script to recompile on changes?

@abdonrd
Copy link
Contributor

abdonrd commented Oct 7, 2018

Also, any plan to setup some TSLint config?

@keanulee
Copy link
Contributor Author

keanulee commented Oct 8, 2018

watch would be nice-to-have for npm start; haven't got around to that yet. PR welcome.

@abdonrd
Copy link
Contributor

abdonrd commented Oct 8, 2018

watch would be nice-to-have for npm start; haven't got around to that yet. PR welcome.

Done at #244!

@keanulee
Copy link
Contributor Author

keanulee commented Oct 8, 2018

TS 3.1 issue - blocked on release of Polymer/polymer#5370 (with updated legacy-element-mixin.d.ts)

Update: I think we need this as well - Polymer/polymer#5371

@felpsio
Copy link

felpsio commented Oct 10, 2018

Sugestion: organize better the js files. The number of files of the directory is 4x bigges because of d.ts, js, js.map. Maybe it would be good to create a new directory just to keep the generated files. I think it also would be a good idea to put a watch flag in tsc so people don't need to run "npm start" often to see the changes
screen shot 2018-10-10 at 16 08 18

@mercmobily
Copy link

@felipecesar42 I agree with that. That's what lit-html does by setting outDir in tsconfig.json

Copy link
Member

@frankiefu frankiefu left a comment

Choose a reason for hiding this comment

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

Looks good!

@keanulee keanulee changed the base branch from master to template-typescript October 10, 2018 21:40
@keanulee keanulee changed the title [do not merge] TypeScript template TypeScript template Oct 10, 2018
@keanulee
Copy link
Contributor Author

Ack the number of files comment. Could consider moving TS source to a ts_src/ directory or similar, with the idea that src/ still contains JS so that polymer serve/polymer build continues to work without further changes. Will leave that for another PR.

CLA ok

@keanulee keanulee merged commit a15f501 into template-typescript Oct 10, 2018
@keanulee keanulee deleted the typescript branch October 10, 2018 21:47
export const UPDATE_PAGE = 'UPDATE_PAGE';
export const UPDATE_OFFLINE = 'UPDATE_OFFLINE';
export const UPDATE_DRAWER_STATE = 'UPDATE_DRAWER_STATE';
export const OPEN_SNACKBAR = 'OPEN_SNACKBAR';
export const CLOSE_SNACKBAR = 'CLOSE_SNACKBAR';

export const navigate = (path) => (dispatch) => {
export interface AppActionUpdatePage extends Action<'UPDATE_PAGE'> {page: string};
Copy link
Contributor

Choose a reason for hiding this comment

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

@keanulee why export these interfaces?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, I guess store.js only uses AppAction, not these interfaces. No good reason, but maybe someone might want to create the action before dispatching it?

const action = actionCreator(param);
store.dispatch(action);

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.

6 participants