aspect-build / aspect-build/rules_ts

[Bug]: Not Checking Transitive Dependencies Package.json "types" field

Open
#429 4 comments 0 reactions 0 assignees View on GitHub
bug need: more info
Dominant language
Starlark
Stars
138
Forks
87
Avg merge
2d 8h
Merged PRs (30d)
3

Description

### What happened?

I am have been having build issues related to incorrect types being produced by my Bazel builds. I have a package where it has a "types" field defined in its package json as "types" : "dist/types/lib/index.d.ts". I am seeing the package build correctly with the index.d.ts files placed correctly.

However when I pull the package into another project and build using Bazel, I produce a new index.d.ts file with the transitive type set to "any". When I build using a different tool (razzle), it is correctly generating the new index.d.ts file with the transitive type set correctly.

I noticed when I go back to the original package and rebuild it using no "declarationDir" in the tsconfig.json, it produces the "index.d.ts" in the root (as expected). Then when I pull the package into my other project, Bazel starts to produce the new index.d.ts with transitive types correctly. This looks like its related to [bazelbuild/rules_nodejs/issues/2044](https://github.com/bazelbuild/rules_nodejs/issues/2044)

### Version

Development (host) and target OS/architectures: MacOs

Output of `bazel --version`: 6.3

Version of the Aspect rules, or other relevant rules from your
`WORKSPACE` or `MODULE.bazel` file: aspect_rules_ts@1.4.5

Language(s) and/or frameworks involved: Typescript

### How to reproduce

```shell
Create a subpackage (call it foo) with a types file located at a non standard location. Example: "dist/types/lib/index.d.ts".

Pull package into project (call it bar) and have it export its type. Example: import {stuff} from "foo"

export const new_stuff = {
...stuff,
//I add more fields here typically
}

After building bar, bar's index.d.ts reads "export declare const new_stuff: any;" Which is incorrect.

bar's index.d.ts should read "export declare const new_stuff: {
field1: string;
field2: string;
... etc.
}"
```

### Any other information?

_No response_

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the foo-to-bar build described in the issue with Bazel 6.3 and aspect_rules_ts@1.4.5. Compare the package.json "types" path and tsconfig.json with and without declarationDir, then inspect the generated bar index.d.ts. Done means transitive types are preserved instead of being emitted as any.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.