CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-flow-remove-types

Fast, zero-configuration Flow type annotation removal tool for JavaScript with CLI and programmatic APIs

84

1.09x
Overview
Eval results
Files

task.mdevals/scenario-9/

Flow Type Assertion Stripper

Build a tool that processes JavaScript source code containing Flow type assertions and removes them to produce standard JavaScript output.

Objective

Create a utility that transforms JavaScript code by removing Flow type assertions (both as Type expressions and as const assertions) while preserving all runtime behavior and code structure.

Requirements

Your tool should:

  1. Accept JavaScript source code as a string input
  2. Remove all Flow type assertions in the form of value as Type
  3. Remove all const assertions in the form of value as const
  4. Return the transformed JavaScript code as a string
  5. Preserve the original code structure, including whitespace and line breaks where possible
  6. Handle nested expressions that contain type assertions
  7. Support type assertions in various contexts (variable declarations, function calls, return statements, etc.)

Input/Output Examples

Example 1: Basic type assertion

// Input
const x = someValue as number;

// Output
const x = someValue;

Example 2: Const assertion

// Input
const config = { name: 'app' } as const;

// Output
const config = { name: 'app' };

Example 3: Multiple assertions

// Input
function process(data) {
  const id = data.id as string;
  const count = data.count as number;
  return { id, count } as const;
}

// Output
function process(data) {
  const id = data.id;
  const count = data.count;
  return { id, count };
}

Test Cases

  • Processes a simple type assertion (value as Type) and removes only the assertion @test
  • Processes a const assertion (value as const) and removes only the assertion @test
  • Handles multiple type assertions in a single code block @test
  • Preserves all non-assertion code exactly as-is @test

Implementation

@generates

API

/**
 * Removes Flow type assertions from JavaScript source code.
 *
 * @param {string} source - The JavaScript source code containing Flow type assertions
 * @returns {string} The transformed JavaScript code with type assertions removed
 */
function stripTypeAssertions(source) {
  // IMPLEMENTATION HERE
}

module.exports = { stripTypeAssertions };

Dependencies { .dependencies }

flow-remove-types { .dependency }

Provides Flow type annotation removal capabilities including type assertion stripping.

Install with Tessl CLI

npx tessl i tessl/npm-flow-remove-types

tile.json