How to define a type of class implementing an interface #3463
Unanswered
joostvdwsd
asked this question in
Q&A
Replies: 2 comments
-
Did you ever find a solution for this? |
Beta Was this translation helpful? Give feedback.
0 replies
-
I'd like to hear more on this topic and the other references floating around for this particular issue. Is the third option what most are going with and is there a gist of a generic approach? How did you solve it? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Affected Languages
TypeScript
orJavascript
Python
Java
C#
,F#
, ...)Go
General Information
The Question
I like to define a type that is a subclass of class x and follows interface Y. This is a pretty standard oo pattern but I can't seem to find a way where the JSII compiler will be happy.
Attempt 1 (Works in typescript but not jsii)
This will give the jsii error: "Type "Foo" cannot be used as an interface"
Attempt 2 (Works in typescript but not jsii)
The above example gives the jsii error: "Non-primitive types without a symbol cannot be processed."
Also attempt # 2 but with the type definitions in generics will give the same error.
Attempt 3 (Works but looses type enforcement)
This last one looses the type enforcement and its not clear that it will check for the interface type.
Question
Is there any way to achieve the type enforcement in the test function for jsii?
Beta Was this translation helpful? Give feedback.
All reactions