fable-compiler / Fable

F# to JavaScript, TypeScript, Python, Rust and Dart Compiler
http://fable.io/
MIT License
2.9k stars 296 forks source link

[TypeScript] Async type signature always returns any #3864

Open leononame opened 2 months ago

leononame commented 2 months ago

Description

Async does not generate correct type signature.

Repro code

REPL

Expected and actual results

It should have some type signature like export const doAsync: Async<string> instead of any, and ideally should be awaitable as well from typescript without giving errors.

Related information

MangelMaxime commented 1 day ago

and ideally should be awaitable as well from typescript without giving errors.

I am not sure if this will be possible because in Fable when you use async we generate a custom async type which have the same behaviour as in .NET.

If you want asynchronous code to be await-able from TypeScrip you should use promise (coming from Fable.Promise) because in this case you will have a real promise.

Regarding the we could indeed type it to:

https://github.com/fable-compiler/Fable/blob/b93f2484e07acc2eb0ce94c3d67c78decb0080ed/src/fable-library-ts/Async.ts#L12-L13