Skip to content

Can't emit types for subclassed abstract class: error TS4094Β #59184

@paulmillr

Description

@paulmillr

πŸ”Ž Search Terms

ts4094, abstract, class, property, protected, private

πŸ•— Version & Regression Information

  • This is a crash
  • Happens in the 5.6-dev, 5.x, 4.x, etc

⏯ Playground Link

https://www.typescriptlang.org/play/?ts=5.6.0-dev.20240708#code/JYWwDg9gTgLgBAbzgZwBYEMBMBWAbHdZOAfTSzzgF84AzKCEOAcgAEA7CAIwBsBTAegxpeyfmRy4mAbgBQvAB6RYcAMYQ2yeOIoBeEttxSgA

πŸ’» Code

Cloneable repo: https://github.com/paulmillr/ts-bug-4094.

So there's abstract class which declares protected property (https://github.com/paulmillr/noble-hashes/blob/main/src/_md.ts#L33):

export abstract class HashMD<T extends HashMD<T>> extends Hash<T> {
  protected buffer: Uint8Array;
}

The class is subclassed (https://github.com/paulmillr/noble-hashes/blob/e804a2f9eff77c92e21705f876d99c3069037988/src/sha256.ts#L31C1-L32C1):

class SHA256 extends HashMD<SHA256> {}

The protected buffer property is not used as emit type anywhere.

https://github.com/paulmillr/noble-hashes/blob/e804a2f9eff77c92e21705f876d99c3069037988/src/_md.ts#L33

πŸ™ Actual behavior

It doesn't compile, error emitted: TS4094: Property 'buffer' of exported class expression may not be private or protected

πŸ™‚ Expected behavior

It should compile

Additional information about the issue

No response

Metadata

Metadata

Assignees

Labels

Domain: Error MessagesThe issue relates to error messagingExperience EnhancementNoncontroversial enhancementsFix AvailableA PR has been opened for this issueWorking as IntendedThe behavior described is the intended behavior; this is not a bug

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions