Skip to content

Conditional types, overloads, and declaration files. #35657

@MicahZoltu

Description

@MicahZoltu

TypeScript Version: 3.6.3

Search Terms:
conditional type overload declaration file

Code
Typescript file:

export class Apple {
	constructor(a: string)
	constructor(a: number)
	constructor(private readonly a: string|number) {}
}

Generated declaration file:

export class Apple {
	constructor(a: string);
	constructor(a: number);
}

Usage:

type AppleArgs = ConstructorParameters<typeof Apple>

Expected behavior:
Whether the usage is inside the same package (.ts file referenced) or another package (.d.ts file referenced) AppleArgs should be [string|number].

Actual behavior:
If the usage is in the same package, AppleArgs is [string|number].
If the usage is in a different package, AppleArgs is [number].

Playground Link: https://www.typescriptlang.org/play/?ssl=1&ssc=1&pln=6&pc=1#code/CYUwxgNghgTiAEkoGdnwIIAdMQQbwCh5jEB7AO2QBcYBXMK0mACigC55qYBLcgcwCUREmApd6jFu3jlaAWwBGIGEIC+BKgE9MCLDhDoYfNAF54AYTE0JTAAqwockFWXIAPFp2kAZhmy4APgIgA
Not a great playground link since this is an issue with declaration emission.

Related Issues: I understand that conditional types (like ConstructorParameters) use the last overload. What I believe is a "bug" here is that the emitted declaration file results in different behavior when the class is referenced from another package vs when it is referenced from the same package. My expectation is that the behavior will be the same in either case.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions