Q:

Extension methods with generics in Dart: Value of type dynamic can't be returned from method

Given this 
extension<T> on List<T> {
  List<T> addAtTheEnd(T value) {
    return this.addAllAtTheEnd(<T>[value]);
  }

  List<T> addAllAtTheEnd(List<T> values) {
    return [
      ...this,
      ...values,
    ];
  }
}

In the code editor the this.addAllAtTheEnd(<T>[value]) is underlined and it's saying:
A value of type 'List<dynamic>' can't be returned from method 'addAtTheEnd' because it has a return type of 'List<T>'.
This does not sound logical to me, as the addAllAtTheEnd method does not have compile errors, I explicitly define the type of generics on the call site (addAtTheEnd) and I am using this to indicate what type I am calling the method on.
Why is this not working and how can I make it work?

A:

Yes, omitting this solves, just like jamesdlin suggested in the comments.

I tested it thoroughly, and these are the results:
This compiles:
...
  List<T> addAtTheEnd(T value) {
    return addAllAtTheEnd([value]);
  }

This does not:
...
  List<T> addAtTheEnd(T value) {
    final thiz = this;
    return thiz.addAllAtTheEnd([value]);
  }

because it is equivalent to the following, where the issue is more clear:
...
  List<T> addAtTheEnd(T value) {
    final List thiz = this;
    return thiz.addAllAtTheEnd([value]);
  }

But declaring the type explicitly works:
...
  List<T> addAtTheEnd(T value) {
    final List<T> thiz = this;
    return thiz.addAllAtTheEnd([value]);
  }

Fun fact: dart linter complains for the solution if you have that lint rule enabled, namely omit_local_variable_types.
So the correct and explicit usage for calling this is the following:
...
  List<T> addAtTheEnd(T value) {
    // ignore: omit_local_variable_types
    final List<T> thiz = this;
    return thiz.addAllAtTheEnd([value]);
  }

If you use it the following way with inline explicit cast:

  List<T> addAtTheEnd(T value) {
    return (this as List<T>).addAllAtTheEnd([value]);
  }

You get a warning for unnecessary cast, where the autofix gladly helps you to convert your code to not be compilable.

