-
Notifications
You must be signed in to change notification settings - Fork 118
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
SyncFunction
type
#35
Comments
Oh, that's pretty useful, floating promises are cancer. I think I don't see a way to do this without type parameter right now. Probably Negated types that are cooking in TS backlog as we speak would solve this: microsoft/TypeScript#29317 |
I don't think this can be achieved without the type parameter either. The declare function ignore<T extends not (object & Promise<any>)>(value: T): void;
declare function readFileAsync(): Promise<string>;
declare function readFileSync(): string;
ignore(readFileSync()); // OK
ignore(readFileAsync()); // Should error |
@all-contributors please add @alcuadrado for ideas |
I've put up a pull request to add @alcuadrado! 🎉 |
Is it possible to do with ESLint rule? https://typescript-eslint.io/rules/no-floating-promises/ |
Hi Crhis!
I'm wondering if it's possible to define a type that forbids async functions. I'll explain why I'd like something like that, and what I tried so far.
Suppose I have a function like this one:
Passing an async function to
receivesACallback
can be problematic, as it doesn'tawait
it.My best try so far is this:
I don't like having to define a useless type param though.
Do you find this idea interesting? And do you know how to do it without the type param?
The text was updated successfully, but these errors were encountered: