Typescript: Unable to implement class with protected members

Created on 18 Mar 2020  路  1Comment  路  Source: microsoft/TypeScript

TypeScript Version: 3.8.3

Search Terms:
implement class protected members

Code

class A {
  protected a: string = '';
}

class B implements A {
  protected a: string = '';
}

Expected behavior:
No errors

Actual behavior:
Error: Class 'B' incorrectly implements class 'A'. Did you mean to extend 'A' and inherit its members as a subclass?
Property 'a' is protected but type 'B' is not a class derived from 'A'.

Playground Link:
https://www.typescriptlang.org/v2/en/play?#code/MYGwhgzhAECC0G8BQ1oAcBOB7ALgU2HwBNowAuaCHDASwDsBzaAXmgHI2BuJAXySVCQYAIWg0AtmhB5xeOjhjxkqTLgLFSFKrUYt2XXkiA

Working as Intended

>All comments

This is the intended behavior, as noted by the fact that there's a special error message just for it 馃槈

Was this page helpful?
0 / 5 - 0 ratings

Related issues

CyrusNajmabadi picture CyrusNajmabadi  路  3Comments

weswigham picture weswigham  路  3Comments

dlaberge picture dlaberge  路  3Comments

zhuravlikjb picture zhuravlikjb  路  3Comments

blendsdk picture blendsdk  路  3Comments