Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Makemeta optional#53

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
wub wants to merge2 commits intoredux-utilities:masterfromwub:master
Closed

Makemeta optional#53

wub wants to merge2 commits intoredux-utilities:masterfromwub:master

Conversation

@wub
Copy link
Contributor

@wubwub commentedFeb 12, 2017
edited
Loading

(Edited) Don't use this PR; it'll cause issues, and better things on the way from the TS team.

Otherwise we have to add `meta: null` to every action
@JaKXz
Copy link
Contributor

Thanks for the patch! For some reason, I'm not seeing good errors on travis, but I tried the test command locally and it printed:

test/typings-test.ts(50,21): error TS2532: Object is possibly 'undefined'.test/typings-test.ts(53,9): error TS2322: Type 'string | undefined' is not assignable to type 'string'.  Type 'undefined' is not assignable to type 'string'.test/typings-test.ts(71,21): error TS2532: Object is possibly 'undefined'.test/typings-test.ts(74,9): error TS2322: Type 'string | undefined' is not assignable to type 'string'.  Type 'undefined' is not assignable to type 'string'.

cc@unional

@wub
Copy link
ContributorAuthor

wub commentedFeb 12, 2017

Oh whoops, that's laziness on my part, I'll fix that!

@coveralls
Copy link

coveralls commentedFeb 12, 2017
edited
Loading

Coverage Status

Coverage remained the same at 100.0% when pulling58840bc on wub:master into5eb76c5 on acdlite:master.

@unional
Copy link
Contributor

I'm not sure if this is the right change.

If you define ameta, do you expect that it can be optional?

If it is optional, then may be one option is to specify it asYourMeta | undefined

wub reacted with thumbs up emoji

@wub
Copy link
ContributorAuthor

wub commentedFeb 12, 2017
edited
Loading

Good point! I find that I don't really usemeta at all.

If I could dox: FSA<foo> instead ofx: FSA<foo, any | undefined> everywhere it would look a bit tidier, but I don't know how complex that would make the typings.

Also, I could just make my owntype X = FSA<foo, any | undefined>, couldn't I.

@unional
Copy link
Contributor

That will be possible when generic default lands.

In the mean time, I don't think overloading would work, but can give it a try

wub reacted with thumbs up emoji

@wub
Copy link
ContributorAuthor

wub commentedFeb 12, 2017

Great, thanks for the feedback@unional. Up to you guys!

@unional
Copy link
Contributor

You are welcome.

It is a touchy point in TypeScript.
In the typings in DT, it usesFSA<Payload> & Meta<Meta> to get around this problem.
However, IMO it does not do it justice as it is really a hack because when you define a FSA with meta, you are thinking of it as one type instead of an interaction of types. But it is IMO and discussion is always welcome.

The current typing is more strict and the good thing about it is that when generic default andundefined as optional is accepted and landed, there won't be any breaking change to the consumer of this library.
We can just loosen up the typings.

Here are references to the issues if you are interested:
microsoft/TypeScript#2175
microsoft/TypeScript#12400

asterikx reacted with thumbs up emojiwub reacted with heart emoji

@JaKXz
Copy link
Contributor

@wub@unional thanks for the discussion, it's been informative to me too. Unless I'm misunderstanding something it seems like this is blocked by those Typescript issues? Specifically though, this point makes the most sense to me:

If you define ameta, do you expect that it can be optional?

I would motion to close this PR in the meanwhile, possibly in favour of another one that "loosens" up the typings... though I'm not sure about what that looks like. TBPH I'm pretty happy with the way things are for now, but if others feel strongly that this needs to change somehow then I'm open to changes. :)

@unional
Copy link
Contributor

FYI generic default is available in ts@next. XD

JaKXz reacted with thumbs up emoji

@wub
Copy link
ContributorAuthor

wub commentedFeb 19, 2017

@JaKXz Cheers! See you on the other side of ts@next ;)

JaKXz reacted with thumbs up emoji

@ghost
Copy link

ghost commentedSep 7, 2017
edited by ghost
Loading

In the JSDocs, andREADME, it's still listed as optional (so isPayload).

/**   * The optional `meta` property MAY be any type of value.   * It is intended for any extra information that is not part of the payload.   */  meta:Meta;

Shouldn't it be the same aserror? (meta?: Meta;)

@zowers
Copy link

will this be resolved?

@unional
Copy link
Contributor

will this be resolved?

Do you mean fixing the readme?

@zowers
Copy link

I mean when the PR will be actually merged or there will be done anything to markmeta as optional

@unional
Copy link
Contributor

unional commentedNov 1, 2017
edited
Loading

As discusses above, keepingmeta as require field provides a more accurate type when you usemeta.
Currently, there is a limitation on TypeScript side that you need to explicitly defineundefined in the generic, but hopefully when it is fixed on TS land, this limitation can be removed and you can just use it asFSA<YourPayload> instead ofFSA<YourPayload, undefined>

zowers reacted with thumbs up emoji

@zowers
Copy link

Oh, cool! Thanks for the explanation, it was not clear from the above comments thatFSA<YourPayload, undefined> is compatible with{ type, payload } (without explicitmeta: undefined)

@wub
Copy link
ContributorAuthor

wub commentedNov 2, 2017

Yeah, sorry,@zowers (and anyone else), my PR is incorrect and will cause issues! I'll edit the parent.

zowers reacted with thumbs up emoji

@JaKXzJaKXz mentioned this pull requestNov 3, 2017
@leesiongchan
Copy link

I thought we can set something like this?

export interface FluxStandardAction<Payload = undefined, Meta = undefined> {  ...}
wub reacted with thumbs up emoji

@wub
Copy link
ContributorAuthor

wub commentedNov 30, 2017

@leesiongchan The first conversation happened before TypeScript 2.3, which introduced defaults for generics (like your example). But yes, we can do that now! I'll submit a request.

leesiongchan reacted with hooray emoji

@wub
Copy link
ContributorAuthor

wub commentedNov 30, 2017

See#94

unional added a commit to komondor-lab/plugin that referenced this pull requestApr 1, 2018
While technically meta can be undefined when not used (to save space).Making it optional means every time you use it you need to check if it is undefined.And since you use it, you assume that your specific action will have meta defined.The same argument asredux-utilities/flux-standard-action#53
unional added a commit to komondor-lab/plugin that referenced this pull requestApr 1, 2018
While technically meta can be undefined when not used (to save space).Making it optional means every time you use it you need to check if it is undefined.And since you use it, you assume that your specific action will have meta defined.The same argument asredux-utilities/flux-standard-action#53
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

6 participants

@wub@JaKXz@coveralls@unional@zowers@leesiongchan

[8]ページ先頭

©2009-2025 Movatter.jp