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

Convert src/ to TypeScript #68

Merged
merged 25 commits into from Feb 18, 2017

Conversation

Projects
None yet
2 participants
@saneyuki
Member

saneyuki commented Feb 17, 2017

Abstract

  • Breaking Change (possible)
  • From some conversation with @azu on Twitter, I tried to convert codes to TypeScript.
  • This changeset includes some changes for build system.
  • This change only does rewrite codes with TypeScript. To publish d.ts in npm, we need push more patch onto this.

Motivation

  • Increase interoperabitily with static typing world like TypeScript or Flowtype.
  • Erase some inconsistency of API system of this library by static checking types of them.

Detailed Design

Change build system

This introduces 2-phase build system.

  1. At 1st phase, Try type checking under src/ with tsc and emit a plain JS code into /__obj/ temp dir.
    In this phase, this also try to copy all javascript file into /__obj/ to keep the content of /src/.
  2. At 2nd phase, Do down-level transform by babel and emit the transformed one into /lib/.

By this change, we can achive to convert our source code to TypeScript incrementally without at giant single patch file.

Unit tese imports from /lib/

By the above change, we need to load the code to test unit tests for incremental converting without changeing
unit tests.

Convert TypeScript

Convert *.js to *.ts simply.

This change escapes from the problem which is that some dependency does not have any d.ts by dirty hacking.

Add *.d.ts and *.js with same name. TypeScript compiler uses *.d.ts to resolve type checking.
But we use *.js file to load a file actually on the runtime. This dirty hack resolves the problem.

Drawback

  • Drop JSDoc.
    • By this change, user who uses Closure Compiler advanced optimization might face to some troubles.
  • Increase Complexity of build system.

Alternative Approach

  • Using Flowtype instead. This is also possible solution.
    But this tries to use TypeScript by conversations with @azu.

Unresolved Items

  • Clean up the build system: #78.
  • Fix some inconsistency of APIs: #71
  • No emit *.d.ts files into /lib/: #78.
  • Disable power-assert temporary: #83
  • Remove jsdoc-to-assert properly: #82
  • No work documentation build by JSDoc:
  • No any linting:
  • Reduce any type from public APIs:
  • Mark Abstract Class/Property as abstract correctly.
  • Relax complex dependency.
    • Some types depends with each other complexly.
@saneyuki

This comment has been minimized.

Show comment
Hide comment
@saneyuki
Member

saneyuki commented Feb 17, 2017

r? @azu

@azu

This comment has been minimized.

Show comment
Hide comment
@azu

azu Feb 17, 2017

Member

Thanks.
I'll look it in this weekend.

Member

azu commented Feb 17, 2017

Thanks.
I'll look it in this weekend.

getState() {
return this._storeGroup.getState();
getState<T>(): T {
return (this._storeGroup as any).getState(); // TODO: remove casting `any`

This comment has been minimized.

@azu

azu Feb 17, 2017

Member

📝 I have no idea about this.
Can we remove this casting by some changes?

@azu

azu Feb 17, 2017

Member

📝 I have no idea about this.
Can we remove this casting by some changes?

This comment has been minimized.

@saneyuki

saneyuki Feb 17, 2017

Member

I thought to introduce some new interfaces which is implemented by StoreGroup or Store to fix it.
Perhaps is it not a right way?

@saneyuki

saneyuki Feb 17, 2017

Member

I thought to introduce some new interfaces which is implemented by StoreGroup or Store to fix it.
Perhaps is it not a right way?

This comment has been minimized.

@azu

azu Feb 17, 2017

Member

Ok, This fix should be later.

@azu

azu Feb 17, 2017

Member

Ok, This fix should be later.

@@ -32,14 +34,14 @@ export let defaultStoreName = "<Anonymous-Store>";
* Store class
* @public
*/
export default class Store extends Dispatcher {
abstract class Store extends Dispatcher {

This comment has been minimized.

@azu

azu Feb 17, 2017

Member

Store is not abstruct in some test case.

const store = new Store();

Is it valid in TypeScript?

Of course, Store is just abstract in most case without testing, I think.
Should we will modify test code?

@azu

azu Feb 17, 2017

Member

Store is not abstruct in some test case.

const store = new Store();

Is it valid in TypeScript?

Of course, Store is just abstract in most case without testing, I think.
Should we will modify test code?

This comment has been minimized.

@saneyuki

saneyuki Feb 17, 2017

Member

Is it valid in TypeScript?

"At this time", it's valid in TypeScript because we keep all unit test cases as plain js.
However, of course, we need to add class TestStore extends Store to them if we convert test cases to TypeScript.

@saneyuki

saneyuki Feb 17, 2017

Member

Is it valid in TypeScript?

"At this time", it's valid in TypeScript because we keep all unit test cases as plain js.
However, of course, we need to add class TestStore extends Store to them if we convert test cases to TypeScript.

@azu

azu approved these changes Feb 17, 2017

Ok. I've checked this PR.

The first overview is looks good to me.
Thanks for nice work.

@@ -48,6 +50,9 @@ export default class Store extends Dispatcher {
return false
}
name: string;
displayName: string;

This comment has been minimized.

@azu

azu Feb 17, 2017

Member

Maybe, displayName is optional.

@azu

azu Feb 17, 2017

Member

Maybe, displayName is optional.

* unique id in each UseCase instances.
*/
id: string;
displayName: string;

This comment has been minimized.

@azu

azu Feb 17, 2017

Member

ditto.
displayName is optional

@azu

azu Feb 17, 2017

Member

ditto.
displayName is optional

@azu azu referenced this pull request Feb 18, 2017

Closed

TypeScript: Add d.ts in npm #70

0 of 2 tasks complete
@azu

This comment has been minimized.

Show comment
Hide comment
Member

azu commented Feb 18, 2017

@azu azu merged commit 5010465 into almin:master Feb 18, 2017

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details

@azu azu referenced this pull request Feb 18, 2017

Closed

add d.ts #1

@saneyuki saneyuki deleted the saneyuki:tsc-port branch Feb 20, 2017

@saneyuki saneyuki referenced this pull request Feb 20, 2017

Closed

Re-enable power-assert #83

@azu azu referenced this pull request Feb 20, 2017

Closed

Almin 0.10 Roadmap #67

@azu azu referenced this pull request Mar 30, 2017

Closed

Convert test/ to TypeScript #144

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment