Skip to content

Add deAsyncify method to TSFunction#871

Draft
codegen-sh[bot] wants to merge 2 commits intodevelopfrom
gen/3bf02c00-53e7-491d-8666-6bbca3a8c8e2
Draft

Add deAsyncify method to TSFunction#871
codegen-sh[bot] wants to merge 2 commits intodevelopfrom
gen/3bf02c00-53e7-491d-8666-6bbca3a8c8e2

Conversation

@codegen-sh
Copy link
Contributor

@codegen-sh codegen-sh bot commented Mar 16, 2025

Description

This PR adds a new deAsyncify method to the TSFunction class, which is the opposite of the existing asyncify method. The new method converts an async TypeScript function to a non-async function by:

  1. Removing the async keyword
  2. Unwrapping the return type from Promise<T> to just T

Implementation Details

  • Added the deAsyncify method to TSFunction class in src/codegen/sdk/typescript/function.py
  • Created comprehensive tests in tests/unit/codegen/sdk/typescript/function/test_function_deasyncify.py covering various scenarios:
    • Basic function conversion
    • Functions with decorators and docstrings
    • Arrow functions
    • Static methods
    • Generic functions
    • Functions with different return types (void, Promise, no return type)

Example Usage

// Before
async function getData(): Promise<string> {
    return "hello";
}

// After calling deAsyncify()
function getData(): string {
    return "hello";
}

This complements the existing asyncify method, giving developers the ability to toggle between async and non-async functions as needed.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


codegen-bot seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

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.

1 participant