Skip to content

fix chainNullableK from option #1589

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

Merged
merged 1 commit into from
Sep 27, 2021
Merged

Conversation

bwlt
Copy link
Contributor

@bwlt bwlt commented Sep 24, 2021

add missing NonNullable

Why:

type A = {
  k?: Array<'hello' | 'world'> | undefined
}

function program<K extends keyof A>(
  k: K,
  fa: O.Option<A>
): NonNullable<A[K]>[number] | undefined {
  // Type 'unknown' is not assignable to type 'NonNullable<A[K]>[number] | undefined'.
  //  Type 'unknown' is not assignable to type 'NonNullable<A[K]>[number]'.
  //    Type 'unknown' is not assignable to type 'string'.ts(2322)
  // |
  return pipe(
    fa,
    O.chainNullableK((a) => a[k]),
    O.chain(A.head),
    O.toUndefined
  )
}

This code does not compile. The expected result should be

function program<"k">(k: "k", fa: O.Option<A>): "hello" | "world" | undefined

add missing NonNullable
@gcanti gcanti merged commit c018624 into gcanti:master Sep 27, 2021
@bwlt bwlt deleted the improve-chainNullableK branch September 27, 2021 08:13
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

3 participants