Skip to content

fix: [build] keep path aliases out of type declarations - #992

Merged
Shreyag02 merged 5 commits into
mainfrom
fix/declaration-path-aliases
Nov 12, 2026
Merged

Shreyag02 merged 5 commits into
mainfrom
fix/declaration-path-aliases

Conversation

@Shreyag02

@Shreyag02 Shreyag02 commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Emitted .d.ts files kept the ~/ path alias from tsconfig.json. Some come from imports such as import type { FilterSelectOption } from '~/types/filters', and TypeScript also writes inferred types as import("~/..."), for example in CodeBlock and MarkdownAdapter. rollup-plugin-tsconfig-paths resolves the alias in the JS output only.

  • Apps cannot resolve these imports. With skipLibCheck: true the types become any, for example DataViewField['filterOptions'], filterType, dataType and the options prop of FilterChip. With skipLibCheck: false they fail with TS2307. In an app with its own ~/* alias they resolve to the app's files.

  • After the bundle is written, tsc-alias rewrites these specifiers in dist to relative paths. It reads the alias from tsconfig.alias.json, which leaves out the react entry of tsconfig.json. The build then fails if a declaration still imports through ~/. The JS output does not change.

  • Replace the placeholder option value 'string' with real values in the DataView and FilterChip test fixtures. FilterValueType is string | number | boolean, so real values type-check.

  • I have followed the pull request section of the contributing guide.

@vercel

vercel Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
apsara Ready Ready Preview Nov 12, 2026 10:38am UTC

@coderabbitai

coderabbitai Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The React Rollup configuration adds a plugin that rewrites aliases in emitted declaration files and fails the build if quoted ~/ specifiers remain. The package adds a TypeScript alias configuration and the tsc-alias development dependency. Two tests change select-option fixture values.

Suggested reviewers: rohanchkrabrty

Merge Risk: Minimal · up to 6e8eb

The change rewrites path aliases in published type declarations to relative paths and updates two test fixtures. No actionable merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "fix: [build] keep path aliases out of type declarations" matches the main change. The PR rewrites ~/ path aliases in emitted .d.ts files to relative paths using tsc-alias, and adds a …
Description check Passed The description explains the problem and the fix. It covers the ~/ alias leaking into .d.ts files, its effect on consumers with skipLibCheck on or off, the tsc-alias rewrite step using `tsconf…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "fix: [build] keep path aliases out of type declarations" matches the main change. The PR rewrites ~/ path aliases in emitted .d.ts files to relative paths using tsc-alias, and adds a build check that fails if any ~/ specifier remains. The test fixture updates are minor and do not need to appear in the title.

Full details: Description check

Explanation

The description explains the problem and the fix. It covers the ~/ alias leaking into .d.ts files, its effect on consumers with skipLibCheck on or off, the tsc-alias rewrite step using tsconfig.alias.json, and the build-time failure check. It also covers the test fixture change from 'string' to real option values. It matches the changeset closely.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 9580a618-688f-4b37-afca-128c2808862e
Commits

Reviewing files that changed from the base of the PR and between 0add681 and 6e8eb69.

Files ignored due to path filters: 1

  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
Files selected for processing: 1

  • packages/react/components/data-view/__tests__/data-view.test.tsx

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@pkg-pr-new

pkg-pr-new Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

pnpm add https://pkg.pr.new/@raystack/apsara@992

commit: 6e8eb69

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's replace the custom plugin with tsc-alias. It reads the ~/ alias from tsconfig, so we do not need to maintain a regex of our own.

  1. Add tsc-alias to devDependencies.
  2. Add packages/react/tsconfig.alias.json:
{
  "extends": "./tsconfig.json",
  "compilerOptions": {
    "paths": {
      "~/*": ["./*"]
    }
  }
}

tsc-alias needs this config. With tsconfig.json, it also rewrites react imports to node_modules/@types/react, because of the react entry in paths.

  1. Run it from closeBundle, and add it after typescript() in createPlugins:
import { replaceTscAliasPaths } from 'tsc-alias';

const resolveDeclarationAliases = () => ({
  name: 'apsara-declaration-aliases',
  closeBundle: () =>
    replaceTscAliasPaths({ configFile: 'tsconfig.alias.json', outDir: 'dist' })
});

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 0add681. Thanks for the suggestion. I switched to tsc-alias and kept a small check that fails the build if a ~/ import is left.

Custom plugin tsc-alias
Alias rules Own regex, does not read tsconfig Reads tsconfig.alias.json
Code to maintain About 40 lines of path logic About 5 lines
Unresolved alias Fails the build Leaves the import as is, build passes
Dependencies None Adds tsc-alias and a second tsconfig
When it runs In the bundle, before files are written On dist after write, once per config (about 0.4s each)
Output '../types/filters' '../types/filters.js'

I went with tsc-alias because it takes the alias rules from tsconfig, so we no longer maintain our own regex. The one thing the old plugin had that tsc-alias does not is the failed build on a leftover alias. So closeBundle now reads every .d.ts in dist after tsc-alias runs and fails the build if it finds one. I tested this with a fake import('~/does-not-exist'), and the build failed with the file and line.

I also type-checked a small app against the built package with bundler and node16 module resolution. Both pass, and the .js paths resolve to their .d.ts files.

@Shreyag02 Shreyag02 self-assigned this Nov 4, 2026
tsc-alias reads the ~/ alias from tsconfig.alias.json, which leaves out
the react entry of tsconfig.json. The plugin fails the build if a
declaration still imports through ~/.
@Shreyag02
Shreyag02 merged commit e57712d into main Nov 12, 2026
8 checks passed
@Shreyag02
Shreyag02 deleted the fix/declaration-path-aliases branch November 12, 2026 10:41

This branch was successfully deployed

1 active deployment
Preview — 6e8eb690 Deployed Nov 12, 2026 by vercel[bot]
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.

2 participants