타입 매개변수로 확장되는 타입 별칭의 supertype 사용

타입 매개변수로 확장되는 타입 별칭의 supertype 사용

Dart 분석기(analyzer)가 만들어 내는 이 진단은, 타입 매개변수로 확장되는 타입 별칭(type alias)을 슈퍼클래스나 슈퍼타입 자리에 사용했을 때 알려줘요. 그런 타입 별칭은 상속 구조에서 쓸 수 없어요.

출처: supertype_expands_to_type_parameter

본문

이 진단은 여러 메시지를 만들 수 있어요:

  • "A type alias that expands to a type parameter can't be implemented." — 타입 매개변수로 확장되는 타입 별칭은 implements 할 수 없어요.
  • "A type alias that expands to a type parameter can't be mixed in." — 타입 매개변수로 확장되는 타입 별칭은 mixin 할 수 없어요.
  • "A type alias that expands to a type parameter can't be used as a superclass constraint." — 타입 매개변수로 확장되는 타입 별칭은 슈퍼클래스 제약으로 쓸 수 없어요.
  • "A type alias that expands to a type parameter can't be used as a superclass." — 타입 매개변수로 확장되는 타입 별칭은 슈퍼클래스로 쓸 수 없어요.

설명

타입 매개변수로 확장되는 타입 별칭이 extends, implements, with, on 절에서 사용되면 이 진단이 나와요.

예시

다음 코드는 타입 매개변수 S로 확장되는 타입 별칭 T가 클래스 Cextends 절에서 사용되기 때문에 이 진단이 나와요:

typedef T<S> = S;

class C extends T<Object> {}

해결 방법

타입 인자의 값을 직접 사용하면 돼요:

typedef T<S> = S;

class C extends Object {}

더 알아보기