Socket
Book a DemoInstallSign in
Socket

@thoughtspot/ts-to-any

Package Overview
Dependencies
Maintainers
13
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@thoughtspot/ts-to-any

A tool to convert TypeScript types to other programming languages.

0.0.1
latest
npmnpm
Version published
Weekly downloads
0
Maintainers
13
Weekly downloads
 
Created
Source

TypeScript to Any Converter

A tool to convert TypeScript types to other programming languages.

Usage

Basic Usage

import {
  TypeScriptConverter,
  createDartConversionConfig,
  Configs,
} from "@thoughtspot/ts-to-any";
import path from "path";

// Option 1: Using Dart-specific config
const converter1 = new TypeScriptConverter({
  conversionConfig: createDartConversionConfig({
    templateRootPath: path.resolve("templates", "dart"),
    useJsonSerializable: true, // Enable JSON serialization support
  }),
  inputConfig: {
    inputFiles: ["src/types.ts", "src/css-variables.ts"],
  },
  logLevel: "Info", // Optional: Set logging level
});

// Option 2: Using default configs
const converter2 = new TypeScriptConverter({
  conversionConfig: Configs.dart,
  inputConfig: {
    inputFiles: ["src/types.ts", "src/css-variables.ts"],
  },
});

// Convert and write to file
const result = converter1.convertAndWriteToFile({
  outPutFile: "types.dart",
});

console.log(result);

Exporting Default Configs

You can export and reuse default configurations in your project. Here's how to set it up:

  • Create a config file (e.g., config.ts):
import {
  createDartConversionConfig,
  Configs as DefaultConfigs,
} from "@thoughtspot/ts-to-any";
import path from "path";

// Option 1: Extend default Dart configuration
export const dartConfig = createDartConversionConfig({
  ...DefaultConfigs.dart,
  templateRootPath: path.resolve("templates", "dart"),
  useJsonSerializable: true,
  additionalTypeMappings: {
    CustomType: "CustomDartType",
    CustomCssVariables: "Map<String, String>",
  },
});

// Option 2: Create custom config from scratch
export const customDartConfig = createDartConversionConfig({
  templateRootPath: path.resolve("templates", "dart"),
  useJsonSerializable: true,
  additionalTypeMappings: {
    CustomType: "CustomDartType",
    CustomCssVariables: "Map<String, String>",
  },
});

// Export all configs
export const Configs = {
  dart: dartConfig,
  customDart: customDartConfig,
  // Add other language configs here
};
  • Use the exported config in your code:
import { TypeScriptConverter } from "@thoughtspot/ts-to-any";
import { Configs } from "./config";

// Using extended default config
const converter1 = new TypeScriptConverter({
  conversionConfig: Configs.dart,
  inputConfig: {
    inputFiles: ["src/types.ts"],
  },
});

// Using custom config
const converter2 = new TypeScriptConverter({
  conversionConfig: Configs.customDart,
  inputConfig: {
    inputFiles: ["src/types.ts"],
  },
});

Configuration Options

Dart Configuration

The createDartConversionConfig function accepts the following options:

type DartConfig = {
  // Path to custom templates (optional)
  templateRootPath?: string;

  // Custom template content (optional)
  templateContent?: Partial<TemplateContent>;

  // Additional type mappings (optional)
  additionalTypeMappings?: Record<string, string>;

  // Enable JSON serialization support (optional)
  useJsonSerializable?: boolean;
};

Default Type Mappings

The converter includes default type mappings for Dart:

{
    "string": "String",
    "number": "int",
    "boolean": "bool",
    "array": "List",
    "object": "Map",
    "function": "Function",
    "any": "dynamic",
    "void": "void",
    "null": "Null",
    "undefined": "Null",
    "true": "bool",
    "false": "bool",
    "Promise": "Future<dynamic>"
}

Custom Type Mappings

You can add custom type mappings to the configuration:

const converter = new TypeScriptConverter({
  conversionConfig: createDartConversionConfig({
    additionalTypeMappings: {
      CustomType: "CustomDartType",
      CustomCssVariables: "Map<String, String>",
    },
  }),
  inputConfig: {
    inputFiles: ["src/types.ts"],
  },
});

Custom Templates

You can provide custom templates by specifying a template root path:

const converter = new TypeScriptConverter({
  conversionConfig: createDartConversionConfig({
    templateRootPath: "./custom-templates/dart",
  }),
  inputConfig: {
    inputFiles: ["src/types.ts"],
  },
});

Features

  • Convert TypeScript types to Dart
  • Support for JSON serialization
  • Custom type mappings
  • Custom templates
  • Configurable logging
  • Multiple input file support

Requirements

  • Node.js
  • TypeScript
  • Required dependencies:
    • @thoughtspot/ts-to-any
    • path (for path resolution)

License

[Add your license information here]

FAQs

Package last updated on 10 Jun 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.