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

[TS] Make AsyncBuilder returns a real type instead of Any #3903

Closed
wants to merge 1 commit into from

Conversation

MangelMaxime
Copy link
Member

I was looking at fixing #3864, and it seems like my fix works for the code provided in the issue:

let doAsync =
    async {
        return "hi"
    }

However, it fails on more complex code and I don't understand why.

Argument of type '(ctx: IAsyncContext<number | undefined>) => void' is not assignable to parameter of type 'IAsync<number>'.
  Types of parameters 'ctx' and 'x' are incompatible.
    Type 'IAsyncContext<number>' is not assignable to type 'IAsyncContext<number | undefined>'.
      Type 'number | undefined' is not assignable to type 'number'.
        Type 'undefined' is not assignable to type 'number'.ts(2345)

I don't understand where TypeScript infer the type to XX | undefined we never seems to use it inside of AsyncBuilder.

@ncave Do you have an idea?

Comment on lines -12 to -13
// Implemented just for type references
export class Async<_T> { }
Copy link
Member Author

@MangelMaxime MangelMaxime Sep 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed because we never use that type, we seems to always refers to IAsync

@ncave
Copy link
Collaborator

ncave commented Sep 27, 2024

Superceded by #3904

P.S. @MangelMaxime Apologies, that was a bit lazy of me, feel free to revert #3904 and resubmit it yourself, if needed.

@ncave ncave closed this Sep 27, 2024
@MangelMaxime
Copy link
Member Author

Oh no problem, the solution was so simple...

I was so focused on looking for | undefined that I didn't see the optional argument in the method 🤦‍♂️

And that's probably what caused me to try to restrict where we typed Async in this PR too.

Thank you for taking a look.

@MangelMaxime MangelMaxime deleted the fix/async_builder_type branch September 28, 2024 13:10
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.

2 participants