镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
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:

No activity

Activity on this issue will appear here.

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