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 bloadvenro commented Oct 18, 2019

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

@vercel
Copy link

vercel 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
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
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
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 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
Copy link
Member

zerobias commented Oct 19, 2019

Great! 👍

@zerobias zerobias merged commit f2b3b94 into effector:master Oct 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants