Skip to content

use typeof on return type with T #22030

Description

TypeScript Version: 2.7.0-dev.201xxxxx

Search Terms:

Code

can we use typeof on return type with T

// @ts-ignore
export function getStatic<T>(target: T): typeof T
{
	// @ts-ignore
	return target.__proto__.constructor;
}

but at real case i have write

// @ts-ignore
export function getStatic<T>(target): T
{
	// @ts-ignore
	return target.__proto__.constructor;
}

export class A
{
	static b()
	{
		console.log('this is static b');
	}

	b()
	{
		console.log('this is b');
	}
}

export let a = new A();
export const c = getStatic<typeof A>(a);

c.b();
a.b();

Expected behavior:

export declare function getStatic<T>(target: T): typeof T;

Actual behavior:

export declare function getStatic<T>(target: T): T;

Playground Link:

Related Issues:

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions