Skip to content

feat: add tsImportExtension config for TypeScript import paths#100

Closed
nicolaturcato wants to merge 1 commit intomainfrom
feat/ts-import-extension
Closed

feat: add tsImportExtension config for TypeScript import paths#100
nicolaturcato wants to merge 1 commit intomainfrom
feat/ts-import-extension

Conversation

@nicolaturcato
Copy link
Copy Markdown

Summary

Adds a new top-level tsImportExtension config option that appends a file extension to relative import paths in generated TypeScript files.

Problem: TypeScript 6 deprecated moduleResolution: "node10", and TypeScript 7 will remove it entirely. Projects using "nodenext" or "node16" resolution require explicit .js extensions on relative imports — but gotsrpc currently generates extensionless imports like:

import * as foo from './vo-constants';

Solution: When tsImportExtension: ".js" is set in the YAML config, generated imports become:

import * as foo from './vo-constants.js';

The option defaults to "" (empty string), so existing behavior is unchanged — this is fully backwards compatible.

Usage

module:
  name: github.com/example/project
  path: ./

tsImportExtension: ".js"

targets:
  # ...
mappings:
  # ...

Changes

  • config/config.go — Add TSImportExtension field to Config struct
  • internal/build/build.go — Pass conf.TSImportExtension through relativeFilePath() → appended after stripping .ts
  • gotsrpc.schema.json — Add tsImportExtension to the JSON schema

Why this matters

  • TypeScript 7 will remove moduleResolution: "node10" — projects need "nodenext" or "bundler"
  • "nodenext" requires .js extensions on relative imports
  • Without this option, consumers must post-process generated files with sed/scripts
  • .js extensions are valid across all TS resolution modes, so opting in is always safe

Add a top-level `tsImportExtension` config field that appends a file
extension (e.g. ".js") to relative import paths in generated TypeScript
files. This is required for TypeScript projects using `moduleResolution:
"nodenext"` or `"node16"`, and prepares for TypeScript 7 which will
remove the deprecated `"node10"` resolution mode.
@nicolaturcato nicolaturcato deleted the feat/ts-import-extension branch April 10, 2026 07:07
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