Skip to content

Paths not respected in declaration files from referenced projectsΒ #62434

@dragomirtitian

Description

@dragomirtitian

πŸ”Ž Search Terms

references

πŸ•— Version & Regression Information

  • This changed between versions 5.8 and 5.9

⏯ Playground Link

https://github.com/dragomirtitian/ts-bug-report-project-references-paths

πŸ’» Code

// @fileName: common.d.ts
export type OnValue = (value: number) => void

// --PRODUCER PROJECT--
// @fileName: producer/tsconfig.json
{
    "compilerOptions": {
        "strict": true,
        "composite": true,
        "module": "nodenext",
        "moduleResolution": "nodenext",
        "paths": {
            "@common": ["../common.d.ts"]
        },
    }
}
// @filename: in-js.d.ts
import { OnValue } from "@common"
export interface ValueProducerDeclaration {
    onValue: OnValue;
}
// @filename: index.ts
export { ValueProducerDeclaration } from "./in-js"
import { OnValue } from "@common"
export interface ValueProducerFromTs {
    onValue: OnValue;
}

// --CONSUMER PROJECT--
// @filename: consumer/tsconfig.json
{
    "compilerOptions": {
        "strict": true,
        "module": "nodenext",
        "moduleResolution": "nodenext",
        "paths": {
            "@producer": ["../producer/index"]
        },
        "declaration": true,
    },
    "references": [
        { "path": "../producer"}
    ]
}

// @filename: consumer/index.ts
import { ValueProducerDeclaration, ValueProducerFromTs } from "@producer"
declare let v: ValueProducerDeclaration;
// n is implicitly any because onValue is actually any (despite what the tooltip says)
v.onValue = (n) => {

}

// n is implicitly number as expected
declare let v2: ValueProducerFromTs;
v2.onValue = (n) => {

}

πŸ™ Actual behavior

In the consumer project v.onValue is essentially any and results in a no implicit any error on n. v2.onValue has the correct type.

πŸ™‚ Expected behavior

v.onValue has correct type and no error occurs on n, as it did in 5.8

Additional information about the issue

The import from @common does not appear to be correctly resolved in the in-js.d.ts file from producer when it is referenced in consumer. If the import is in index.ts (a ts file) in producer it all works as expected.

Adding the same path in consumer also fixes the issue, so it appears that paths from the consumer are being used to resolve imports in declarations from the producer.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions