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
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Fable.Transforms/Fable2Babel.fs
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,8 @@ module Annotation =
// Move this to Replacements.tryEntity?
let tryNativeOrFableLibraryInterface com ctx genArgs (ent: Fable.Entity) =
match ent.FullName with
| "Microsoft.FSharp.Control.FSharpAsync`1" ->
makeFableLibImportTypeAnnotation com ctx genArgs "AsyncBuilder" "IAsync" |> Some
| _ when not ent.IsInterface -> None
| Types.icollection -> makeNativeTypeAnnotation com ctx genArgs "Iterable" |> Some
// -> makeFableLibImportTypeAnnotation com ctx [Fable.Any] "Util" "ICollection"
Expand Down
9 changes: 8 additions & 1 deletion src/Fable.Transforms/Replacements.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3500,7 +3500,14 @@ let asyncBuilder (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Exp
Helper.InstanceCall(x, "Using", t, [ arg; f ], i.SignatureArgTypes, genArgs = i.GenericArgs, ?loc = r)
|> Some
| Some x, meth, _ ->
Helper.InstanceCall(x, meth, t, args, i.SignatureArgTypes, genArgs = i.GenericArgs, ?loc = r)
let typ =
// Progressively add types to AsyncBuilder
// "Delay" is what is exposed to the end user, so for now we only care about it
match meth with
| "Delay" -> t
| _ -> Any

Helper.InstanceCall(x, meth, typ, args, i.SignatureArgTypes, genArgs = i.GenericArgs, ?loc = r)
|> Some
| None, meth, _ ->
Helper.LibCall(
Expand Down
5 changes: 0 additions & 5 deletions src/fable-library-ts/Async.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ import { protectedReturn } from "./AsyncBuilder.js";
import { FSharpChoice$2_$union, Choice_makeChoice1Of2, Choice_makeChoice2Of2 } from "./Choice.js";
import { TimeoutException } from "./SystemException.js";

// Implemented just for type references
export class Async<_T> { }
Comment on lines -12 to -13
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


function emptyContinuation<T>(_x: T) {
// NOP
}
Expand Down Expand Up @@ -203,5 +200,3 @@ export function startAsPromise<T>(computation: IAsync<T>, cancellationToken?: Ca
startWithContinuations(computation, resolve, reject, reject,
cancellationToken ? cancellationToken : defaultCancellationToken));
}

export default Async;
Loading