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

Types: derive actions type from the symbiotes type #32

Merged
merged 4 commits into from
Oct 18, 2019
Merged

Types: derive actions type from the symbiotes type #32

merged 4 commits into from
Oct 18, 2019

Conversation

Finesse
Copy link
Contributor

@Finesse Finesse commented Oct 15, 2019

Resolves #28

Sorry for the long delay, I was quite busy.

Now one doesn't need to write the action types, TypeScript does it automatically:

interface State {
  value: string;
}

const symbiotes = {
  foo(state: State) {
    return {...state, value: 'foo'};
  },
  bar(state: State, value: number) {
    return {...state, value: `bar ${value}`};
  }
};

const {actions, reducer} = createSymbiote({value: 'Hi'}, symbiotes);

actions.bar('cocktail'); // TS error, a number is expected
reducer({ value: 42 }, actions.foo()); // TS error, the value property must be a string
reducer({ value: 'Hi!' }, actions.bar(12)); // TS: 👍

I failed to implement the symbiotes optional arguments support in TypeScript 2.8 so I had to set the minimal TypeScript version to 3.0 in daacb43. Also this upgrade has allowed to implement a more simple and robust solution. I think this change is not critical because the version 3.0 is only 2 month younger than 2.8 and migrating from TypeScript 2 to 3 is not a big deal.


IssueHunt Summary

Referenced issues

This pull request has been submitted to:


IssueHunt has been backed by the following sponsors. Become a sponsor

@ghost
Copy link

ghost commented Oct 15, 2019

DeepCode Report (#bce8d1)

DeepCode analyzed this pull request.
There are no new issues.

@coveralls
Copy link

coveralls commented Oct 15, 2019

Pull Request Test Coverage Report for Build 148

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 100.0%

Totals Coverage Status
Change from base Build 145: 0.0%
Covered Lines: 110
Relevant Lines: 110

💛 - Coveralls

@sergeysova
Copy link
Owner

Have you finished?

@Finesse
Copy link
Contributor Author

Finesse commented Oct 18, 2019

Have you finished?

Yes

@sergeysova sergeysova merged commit 970629b into sergeysova:master Oct 18, 2019
@sergeysova
Copy link
Owner

Thank you

@sergeysova
Copy link
Owner

@all-contributors please add @Finesse for code

@allcontributors
Copy link
Contributor

@sergeysova

I've put up a pull request to add @Finesse! 🎉

@Finesse
Copy link
Contributor Author

Finesse commented Oct 19, 2019

@sergeysova How to get my $5 from IssueHunt?

@sergeysova
Copy link
Owner

@Finesse done

@Finesse
Copy link
Contributor Author

Finesse commented Oct 25, 2019

@sergeysova Thank you!

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.

Types: derive actions type from the symbiotes type
3 participants