set_ element_ type_ not_ assignable
Details about the 'set_element_type_not_assignable' diagnostic produced by the Dart analyzer.
The element type '{0}' can't be assigned to the set type '{1}'.
Description
#The analyzer produces this diagnostic when an element in a set literal has a type that isn't assignable to the element type of the set.
Example
#
The following code produces this diagnostic because the type of the string
literal '0' is String, which isn't assignable to int, the element
type of the set:
var s = <int>{'0'};
Common fixes
#If the element type of the set literal is wrong, then change the element type of the set:
var s = <String>{'0'};
If the type of the element is wrong, then change the element:
var s = <int>{'0'.length};
Unless stated otherwise, the documentation on this site reflects Dart 3.10.3. Report an issue.