Skip to content
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

Using generic type as Type #1010

Closed
CareF opened this issue Jun 6, 2020 · 1 comment
Closed

Using generic type as Type #1010

CareF opened this issue Jun 6, 2020 · 1 comment
Labels
request Requests to resolve a particular developer problem state-duplicate This issue or pull request already exists

Comments

@CareF
Copy link

CareF commented Jun 6, 2020

Currently we cannot use generic types as Type argument. For example if I have a function foo(Type t), foo(int) and foo(Object) are valid, but foo(List<int>) is not, with error message

Error: A comparison expression can't be an operand of another comparison expression.

I don't know if there's any reason to parse< in (List<int>) as comparison.

I am told that one workaround is:

class TypeOf<T> {
  Type get type => T;
}

TypeOf<List<int>>().type

or

Type typeOf<T> () => T;

typeOf<List<int>>()

Another way I did is using <int>[].runtimeType.

One problem with all these solutions are it cannot generate a const Type.

But I'm thinking maybe including such parser would be more elegant in the language.

@CareF CareF added the request Requests to resolve a particular developer problem label Jun 6, 2020
@lrhn lrhn added the state-duplicate This issue or pull request already exists label Jun 8, 2020
@lrhn
Copy link
Member

lrhn commented Jun 8, 2020

Duplicate of #123

(So we are aware of the issue, but there is currently no solution).

@lrhn lrhn closed this as completed Jun 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
request Requests to resolve a particular developer problem state-duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants