-
Notifications
You must be signed in to change notification settings - Fork 220
Closed
Labels
featureProposed language feature that solves one or more problemsProposed language feature that solves one or more problems
Description
Realizes #66, Feature specification
Sample typedef & usage:
typedef IntList = List<int>;
IntList il = [1,2,3];
Related issues: dart-lang/sdk#2626
zoechi, rich-j, srawlins, sureshg, mnordine and 437 moremorr0ne, gabrielpacheco23, sarrietav-dev, hayderux and josiahsrcrhalff, tenhobi, calvinnfernando, mpfaff, dcharkes and 38 moreamsakanna, jeroen-meijer, hersveit, nightscape, nesscx and 107 moreRdeWilde, matuella, eli1stark, edwjusti, mateusfccp and 30 morejoaomarcos96, slightfoot, drexel-ue, jonahwilliams, wrozwad and 14 more
Metadata
Metadata
Assignees
Labels
featureProposed language feature that solves one or more problemsProposed language feature that solves one or more problems
Type
Projects
Status
Done
Milestone
Relationships
Development
Select code repository
Activity
eernstg commentedon Oct 31, 2018
Specification CL at https://dart-review.googlesource.com/c/sdk/+/81414.
eernstg commentedon Nov 1, 2018
Feature specification proposal in this PR.
eernstg commentedon Nov 6, 2018
Said feature specification landed as efdc2fa.
eernstg commentedon Nov 8, 2018
PR created for the feature specification: One rule needs to be discussed, and the right thing to do is to say explicitly that no conclusion has been reached yet, with respect to that particular rule.
leafpetersen commentedon Nov 8, 2018
I opened an issue for discussion of the question of using typedefs where classes are expected here.
eernstg commentedon Nov 9, 2018
Said PR now landed.
leafpetersen commentedon Nov 28, 2018
I think we need to update the spec to reflect the consensus on static method access.
eernstg commentedon Nov 30, 2018
Landed #116 for that.
90 remaining items
Levi-Lesches commentedon Jul 22, 2021
Now that I actually want to use this feature (with JSON types, surprise surprise), I came across a problem: Where do I actually put the typedef?
In my Flutter app, I have this file structure:
If I want classes
A
,B
, andC
, each in their respective files, where should I put theJson
alias? Seems like a lot of overhead to add ajson_alias.dart
file just for that. If I put it in each of the data files, then there will be conflicts. And I don't want to put it in any one data file, sinceJson
isn't intrinsic to any specific class. If I put it indata.dart
, then all importers can see it, but none of the data files can use it in their definitions!@eernstg, thoughts? Are there any tests that happen to import aliases that I can pull inspiration from?
munificent commentedon Jul 22, 2021
I would probably do this.
Levi-Lesches commentedon Jul 23, 2021
Okay, thanks for the recommendation, I'll do that.
Zabadam commentedon Jul 24, 2021
If you will be using more typedefs, a suggestion would be an encompassing root-leveltypedefs.dart
; it doesn't need to be exported.I have seen a lot of packages that would, in your scenario, have a
src/data/common.dart
solution, importingcommon
into eacha
,b
, andc
.lalomartins commentedon Jul 24, 2021
Folks, this is all very interesting but Github bug comments are not the right space for it.
fanthus commentedon Aug 3, 2021
I tried this feature in IntelliJ dart plugin , like it still not support.
eernstg commentedon Aug 3, 2021
@fanthus, if you wish to report an issue with the IntelliJ plugin and non-function type aliases, please create an issue with 'area-intellij' and give more details.
esenmx commentedon Aug 28, 2021
Can it be possible to get the name of typedef instead the underlying runtimeType in future? Since it's just an alias, I think it might be feasible with an extra field for variables with typedefs.
Why I would need this?
Most of the time, I use
runtimeType
for labeling things in logs. But for typedefs it's not a case obviously. Example:runtimeType is
Provider<String>
but there could be way to printProvider<SessionID>
which is much more identifiable.Also it would be very beneficial for writing something like
golang
styletype-switch
.creativecreatorormaybenot commentedon Aug 28, 2021
@esenmx The way you describe it, it is a new type rather than an alias. I guess the problem is that
extends String
does not work, but it is not an alias if you can switch on it.