Skip to content

ConstructorParameters<T> cannot get correct types of overloaded constructor #37079

@meteorlxy

Description

@meteorlxy

TypeScript Version: 3.8.2

Search Terms: ConstructorParameters, overload

Code

interface Options {
	a: string;
	b: string;
}

class Foo {
	constructor(a: string, b: string);
	constructor(options: Options);
	constructor(options: Options | string, b?: string) {
		// implement
	}
}

// Expected: type Params = [Options] | [string, string]
// Actual: type Params = [Options]
type Params = ConstructorParameters<typeof Foo>;

const paramArray: Params = ['foo', 'bar']; // error
const paramObj: Params = [{ a: 'foo', b: 'bar' }]; // ok

Expected behavior:

type Params = [Options] | [string, string]

Actual behavior:

type Params = [Options]

Playground Link: playground link

Related Issues:

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions