Skip to content

TS2339: Property '__proto__' does not exist on type 'typeof A1'. #30587

@bluelovers

Description

@bluelovers

TypeScript Version: 3.4.0-dev.201xxxxx

Search Terms:

Code

maybe this should call as Feature request

import util = require('util')

export class P
{
	fn1(v: string)
	{
		return 1
	}

	static create()
	{
		console.log('P', util.inspect(this));

		console.log('this.prototype.fn1', this.prototype.fn1);
		// @ts-ignore
		console.log('this.prototype.fn2', this.prototype.fn2);

		// here has more code

		return new this
	}
}

export class A1 extends P
{
	fn1(v: string | number)
	{
		return 1
	}

	fn2(v: string | number)
	{
		return 1
	}

	static create(): A1
	{
		// TS2339: Property '__proto__' does not exist on type 'typeof A1'.
		let superStatic = this.__proto__;

		console.dir(superStatic);
		console.dir(superStatic.create);

		return superStatic.create.call(this)
	}
}

console.log(A1.create().fn2(1));

Expected behavior:

no error, and typescript know superStatic is typeof P


Feature request here

hope can have something like

static create(): ThisType<this>

make without always write

static create(): XXX

or a way to get P from A1 , when we didn't know who is A1 parent class in static

Actual behavior:

TS2339: Property '__proto__' does not exist on type 'typeof A1'.

Playground Link:

Related Issues:

Metadata

Metadata

Assignees

No one assigned

    Labels

    DeclinedThe issue was declined as something which matches the TypeScript visionSuggestionAn idea for TypeScript

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions