-
Notifications
You must be signed in to change notification settings - Fork 247
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
Identical static methods in parent/child classes are mistakenly recognized as invalid in JSII #3410
Comments
Allowing this might result in signatures that are impossible to accurately represent in future languages we might want to add, such as Rust and Swift, where there may be an interest in representing static members as class-implemented traits (would be useful in user-land, but AFAIK does not allow specialization). That means if we allow this and represent it in languages where possible (that is - all supported languages at this point, AFAIK), we might end up forced to represent a different (less specific) API in some future languages... Making it easy for API developers to overlook the developer experience implications to this... I'm not entirely against implementing this change, but then we should also consider whether we should extend the same courtesy to C# (i.e: generating the override declaration it supports, with a less specific signature than in the original code). I would encourage writing a basic RFC for this to ensure we have evaluated the current & future customer implications of this change. |
I seem to be hitting a similar issue as this, except the types are actually identical. In module A: export type MetricWithAlarmSupport = Metric | MathExpression;
export class MetricFactory {
adaptMetric(metric: MetricWithAlarmSupport): MetricWithAlarmSupport {
...
}
} In module B: import { MetricWithAlarmSupport, MetricFactory } from "module-a";
export class MyMetricFactory extends MetricFactory {
adaptMetric(metric: MetricWithAlarmSupport): MetricWithAlarmSupport {
...
}
} Results in errors like:
Replacing the Is this related to this issue, or should I file another one? |
@echeung-amzn Hmm, that sounds like it might be another bug. If you could file a separate issue for it that would be great! It would be especially helpful if you can write a minimal repro. (You can use projen to bootstrap a new jsii project if needed). |
🐛 Bug Report
Related issues: #3407, #2358
Affected Languages
TypeScript
orJavascript
Python
Java
C#
,F#
, ...)Go
General Information
What is the problem?
When compiling with JSII, overriding static methods on child classes with different return types results in an error, even when the types are technically compatible. For example:
produces an error like:
Since
DerivedValue
extendsBaseValue
, this compiles in TypeScript and is valid ES6 code. This kind of structure is also valid in Java:In C# I think this is also valid, but this needs validation. I suspect it's valid based on this comment in our docs:
In Python, I think @ classmethod's can be directly overriden so I don't think this causes any issues. (can anyone confirm?)
In Go there's no real "static" methods, so the transpiled code from jsii should also be valid.
Verbose Log
N/A
The text was updated successfully, but these errors were encountered: