Quantcast
Channel: Dart - How to create custom types on the fly like in Typescript? - Stack Overflow
Browsing all 4 articles
Browse latest View live

Answer by Andrea Rossi for Dart - How to create custom types on the fly like...

Yes, today you can use typedefs from 2.13 dart versiontypedef IntList = List<int>;IntList il = [1, 2, 3];https://dart.dev/language/typedefs

View Article



Answer by Rick Gladwin for Dart - How to create custom types on the fly like...

Another way to enforce custom types in Dart is to use assertions in a constructor (when your custom type is being used).class SomeClass { final String someVariable SomeClass(this.someVariable) :...

View Article

Answer by Michael Horn for Dart - How to create custom types on the fly like...

Original Answer (see updates below): This isn't possible at the language level in Dart - There are a couple alternatives though.You could simply define an enum along with a method to derive a string...

View Article

Dart - How to create custom types on the fly like in Typescript?

I want to create a custom type in Dart like I would do in typescript. This type should be a subtype of String, accepting only some values.For example, in Typescript I would do:type myType = 'HELLO' |...

View Article
Browsing all 4 articles
Browse latest View live




Latest Images