Skip to content

Use of "private" properties prevents multiple versions of a module in the same closure #979

@eladb

Description

@eladb

Due the fact that when a class has private/protected members, TypeScript uses nominal type checking instead of structural type checking, different versions of the same class would not be compatible.

See details and example in microsoft/TypeScript#28128.

Bottom line, it appears that using "private" members is not practical for class libraries since it means classes cannot be used across versions and it is a common use case for ecosystems to have multiple versions of the same class in an application's closure.

To ensure that this cannot happen with the CDK and AWS Construct Library, I am proposing that jsii will not allow the use of TypeScript's private modifier. Instead it will recommend that users prefix a member with an underscore _, which will be hidden from jsii languages and is a common practice in JavaScript to denote private members.

The next step to enable multiple major versions is to allow jsii-runtime to load multiple versions into a module's closure. At the moment it is prohibited (aws/jsii#61).

Metadata

Metadata

Assignees

Labels

bugThis issue is a bug.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions