castUiFactory<T extends UiProps> function

UiFactory<T> castUiFactory<T extends UiProps>(
  1. dynamic value
)

Casts value to UiFactory<T>, which can be inferred from the surrounding context, allowing you to perform casts of dynamic values without having to repeat the type or worry about how formatting affects ignore comment placement.

Example:

// Explicit cast
UiFactory<FooProps> Foo =
   // ignore: undefined_identifier
   _$Foo as UiFactory<FooProps>;

// This utility
UiFactory<FooProps> Foo = castUiFactory(_$Foo); // ignore: undefined_identifier

Casting the generated factory is necessary because, until code generation is run, the generated factory is of type dynamic, meaning that the following code would emit an implicit_cast error (which can't be ignored as of Dart 2.9):

UiFactory<FooProps> Foo = _$Foo; // ignore: undefined_identifier

This works around those limitations by reducing the amount of code necessary to cast the generated factory.

NOTE: When declaring a component factory, using this utility is the supported approach. The builder and other tooling may not work as expected without using it (even with an explicit cast).

Implementation

UiFactory<T> castUiFactory<T extends UiProps>(dynamic value) => value as UiFactory<T>;