type_annotation_deferred_class
The deferred type '{0}' can't be used in a declaration, cast, or type test.
Description
#The analyzer produces this diagnostic when the type annotation is in a
variable declaration, or the type used in a cast (as
) or type test (is
)
is a type declared in a library that is imported using a deferred import.
These types are required to be available at compile time, but aren't.
For more information, check out Lazily loading a library.
Example
#The following code produces this diagnostic because the type of the
parameter f
is imported from a deferred library:
import 'dart:io' deferred as io;
void f(io.File f) {}
Common fixes
#If you need to reference the imported type, then remove the deferred
keyword:
import 'dart:io' as io;
void f(io.File f) {}
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。