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

Result.combine inferred incorrectly when input is nested array #441

Closed
h-yon opened this issue Jan 5, 2023 · 3 comments
Closed

Result.combine inferred incorrectly when input is nested array #441

h-yon opened this issue Jan 5, 2023 · 3 comments

Comments

@h-yon
Copy link

h-yon commented Jan 5, 2023

Result.combine is not correctly inferred in the following code with v6.0.0.

import { ok, Result } from 'neverthrow'

const tuple = <T extends unknown[]>(...args: T): T => args

const string = ok('string')
const number = ok(1)

const numbers1 = Result.combine([...Array(1).keys()].map(ok))
const numbers2 = Result.combine([...Array(2).keys()].map(ok))
const numbers3 = Result.combine([...Array(3).keys()].map(ok))
const numbers4 = Result.combine([...Array(4).keys()].map(ok))

// ↓ should be Result<[string, number, number[], number[], number[], number[]], never> but inferred as Result<never, never>
const values = Result.combine(tuple(string, number, numbers1, numbers2, numbers3, numbers4))

I made sample repo to reproduce: https://github.com/h-yon/nt-test

Curiously, this problem does not occur when downgrading to v5.0.1 or reducing variable

@brndt
Copy link

brndt commented Mar 31, 2023

Yes, also if you have more than five elements in array it infers type as Result<never, never>:

const test = Result.combine([ok(1), ok(1), ok(1), ok(1), ok(1), ok(1)])
// const test: Result<never, never>

@supermacro
Copy link
Owner

supermacro commented Apr 17, 2023

The issue is that currently there's a recursion depth limit of 5 iterations. See #468, where I increase the iteration count to 50 - meaning now neverthrow would be able to have inference of tuples containing up to 50 elements.

@supermacro
Copy link
Owner

https://github.com/supermacro/neverthrow/releases/tag/v6.0.1-0

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

No branches or pull requests

3 participants