-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Allow type arguments in class literals #11923
Comments
Added Area-Language, Triaged labels. |
Parsing could be harder in that case. What is: |
This comment was originally written by @seaneagan issue #1321 says chained comparisons will not be supported, and as noted there, in this case I think the associated syntax should not be allowed in the context of comparisons, since it leads to calling a relational operator on a boolean which doesn't makes sens. In which case: x < y > -1 would not represent any comparisons, but rather calling the - operator on the class literal x<y> with argument 1. |
This comment was originally written by @seaneagan On second thought, that syntax is useful for DSLs, so it should be allowed. In which case, maybe the best we can do is: to fix issue #2626 which would allow: typedef StringList = List<String>; ... expect(x, isA(StringList)); and then maybe sweeten it up a little bit, by allowing inline typedefs: expect(x, isA(typedef List<String>)); |
On the one hand, one would like to have literals for all types. On the other hand, this is a rat hole (as anything related to generics invariably is). Set owner to @gbracha. |
Issue #18758 has been merged into this issue. |
Issue #18757 has been merged into this issue. |
Issue #20027 has been merged into this issue. |
There is a request for this feature in Angular: angular/angular#1691 |
Issue #23221 has been merged into this issue. |
I made a S/O question about this recently: https://stackoverflow.com/questions/52891537/how-to-get-generic-type The answer provides a pretty good solution: Type typeOf<T>() => T;
main() {
Type type = typeOf<MyClass<int>>();
print(type);
} Kudos to Xavier |
Any updates? I'm discussing adding macros on dart-lang/language#1482, and one of the big issues (I suppose for Macro getMacro() {
final Type type = getType(); // some other function to return a type
return Macro<type>(); // ERROR: The name 'type' isn't a type so it can't be used as a type argument.
} Among other uses. |
@Levi-Lesches, I think your comment belongs somewhere else. This issue requests the ability to use a parameterized type (that is, a term of the form The language proposal to add this feature is dart-lang/language#123, and the standard workaround was shown by @rrousselGit here. I'll close this issue because it is a language feature proposal, and they live in the language repository today, but if we were to transfer this issue to the language repository then it would be a duplicate of dart-lang/language#123. |
Ah okay I misunderstood. I realized anyway that by allowing a variable type as a generic, there could be massive problems with type-safety. |
This issue was originally filed by @seaneagan
We have class literals e.g. List, but they do not allow using generics, e.g. List<String>. One use case is issue #10407, being able to do:
instead of just:
[Edit Mar 2021 eernstg: Closing this issue as a duplicate of dart-lang/language#123. This one is older indeed, but today dart-lang/language#123 is used to discuss this feature proposal.]
The text was updated successfully, but these errors were encountered: