Skip to content
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

Better `forward` typings (TS) #229

Merged
merged 6 commits into from Oct 19, 2019
Merged

Conversation

@bloadvenro
Copy link
Contributor

bloadvenro commented Oct 18, 2019

Fixed wrong forward typings behavior, when forwarding FROM "less strict" type TO "more strict" type throws no errors.

@now

This comment has been minimized.

Copy link

now bot commented Oct 18, 2019

This pull request is being automatically deployed with ZEIT Now (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://zeit.co/zerobias/effector/iusx0eiga
🌍 Preview: https://effector-git-fork-bloadvenro-forward-typings.zerobias.now.sh

@bloadvenro

This comment has been minimized.

Copy link
Contributor Author

bloadvenro commented Oct 18, 2019

Also added tests for providing both generics (as you asked me in our community) to avoid accidental breaking change in future.

@bloadvenro

This comment has been minimized.

Copy link
Contributor Author

bloadvenro commented Oct 18, 2019

@abliarsar proposed an idea how to make forward inference even better :)

  it('should forward from `Unit<*>` to `Unit<void>`', () => {
    const from = createEvent<string>()
    const to = createEvent<void>()

    forward({from, to}) // <-- NOW FIXED
...
@bloadvenro bloadvenro changed the title Forward typings Forward typings (TS) Oct 18, 2019
@bloadvenro

This comment has been minimized.

Copy link
Contributor Author

bloadvenro commented Oct 18, 2019

Remark:

const str = createEvent<string>()
const strOrNum = createEvent<string | number>()

// TS v3.5.3 (current version in effector repo)
//
// Produces an error:
//
// Type 'Event<string | number>' is not assignable to type 'Unit<string>'.
//     ...
forward({
  from: strOrNum,
  to: str
})

// TS v3.6.3 (current stable TS version)
//
// Produces an error:
//
// No overload matches this call.
//     ...
forward({
  from: strOrNum,
  to: str
})

This is just a note.

@bloadvenro bloadvenro force-pushed the bloadvenro:forward-typings branch from 421acd1 to e5f9878 Oct 18, 2019
@bloadvenro bloadvenro changed the title Forward typings (TS) Better forward typings (TS) Oct 18, 2019
@bloadvenro bloadvenro changed the title Better forward typings (TS) Better `forward` typings (TS) Oct 18, 2019
@zerobias

This comment has been minimized.

Copy link
Owner

zerobias commented Oct 19, 2019

Great! 👍

@zerobias zerobias merged commit f2b3b94 into zerobias:master Oct 19, 2019
4 checks passed
4 checks passed
common-tests common-tests
Details
WIP Ready for review
Details
now Deployment has completed
Details
semaphoreci The build passed on Semaphore.
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.