Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support property type overrides when override type is compatible with parent type #37

Open
jasongwartz opened this issue Mar 30, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@jasongwartz
Copy link
Contributor

pkl-typescript currently doesn't support generating child classes that override the type of a property from the parent class.

The README currently says:

TypeScript interfaces, when using extends to extend a parent type, do not support overriding the type of a property from the parent.

This is actually only sort-of true - TypeScript does allow overriding a property type when the new type is compatible with the parent type (eg. narrowing string to a string literal type).

If it's possible to detect this compatibility in Pkl reflection, we should allow this particular subclassing behaviour.

@jasongwartz jasongwartz added the enhancement New feature or request label Mar 30, 2024
@jasongwartz
Copy link
Contributor Author

Ref:

else if (superProp == null || isSameType(superProp.type, prop.type)) true
and
local function isSameType(typeA: reflect.Type, typeB: reflect.Type) =

@jasongwartz
Copy link
Contributor Author

Partially resolved by: #38 (for string-type to string-literal type)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant