typescript-yield

raw JSON →
0.1.2 verified Fri May 01 auth: no javascript deprecated

A transpiler that enables use of ES6 yield statements in TypeScript before native support was available. Version 0.1.2 is a proof-of-concept with limited documentation. It transforms yield-based async patterns (often used with the 'suspend' library) into plain JavaScript. The tool requires manual preparation of type definition files and forbids the use of 'yield' anywhere else in the codebase. It has been largely superseded by native async/await and TypeScript's built-in generator support. Not recommended for new projects.

error TypeError: yield is not a function
cause Trying to call 'yield' at runtime without transpiling first.
fix
Run 'ts-yield' on your source files before compilation. 'yield' is only available after transpilation.
error error TS2304: Cannot find name 'yield'
cause TypeScript compiler doesn't recognize 'yield' as a function.
fix
Add a type declaration for 'yield' (e.g., declare function yield(...args: any[]): any;) or run the transpiler before tsc.
error error TS2322: Type 'void' is not assignable to type 'boolean'
cause The async function's return type is not inferred correctly after transpilation.
fix
Manually adjust the return type annotation on the async function, or ensure the transpiler output functions have correct signatures.
deprecated typescript-yield is no longer maintained; use async/await or TypeScript generators.
fix Prefer native async/await or TypeScript's built-in generator support (function*).
gotcha The word 'yield' cannot be used anywhere else in the codebase (e.g., in strings or as a variable name).
fix Avoid using 'yield' outside of the transpiler context; rename variables or use alternative wording.
gotcha The transpiler modifies TypeScript source files in-place; no backup is created by default.
fix Always work on a copy of your files, or version-control before running the transpiler.
breaking The tool expects a specific pattern: yield(func(args...), resume()). Other patterns may not transpile correctly.
fix Ensure all async calls follow the exact yield + resume pattern as shown in documentation.
npm install typescript-yield
yarn add typescript-yield
pnpm add typescript-yield

Shows how to use typescript-yield with the suspend library: define async function with callback, then use yield and resume.

// Install: npm install typescript-yield suspend
// Prepare a TypeScript file (e.g., src/example.ts):
/// <reference path='../node_modules/typescript-yield/...' />

var async = require('suspend').async;

var foo = async(function(param: boolean): boolean {
    return true;
});

var a: boolean = yield(foo(true), resume());

// Transpile: npx ts-yield -o build src/**.ts
// Then compile with tsc