Skip to content

Commit ffe9682

Browse files
committed
docs: add warning about type constraints in tree converters
1 parent a179f01 commit ffe9682

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

docs/basics/converters.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ dogs.registerTreeBaseFactory(
9292

9393
You can register a custom tree base factory using the `registerTreeBaseFactory` method of the `DogEngine`.
9494

95+
9596
```{ .dart title="Map Converter using NTreeArgConverter" }
9697
final mapFactory = TreeBaseConverterFactory.createNargsFactory<Map>(
9798
nargs: 2, consume: <K, V>() => MapNTreeArgConverter<K, V>()
@@ -115,6 +116,13 @@ class MapNTreeArgConverter<K,V> extends NTreeArgConverter<Map> {
115116
}
116117
}
117118
```
119+
120+
!!! warning "Don't use Type Constraints"
121+
Since tree converters are dynamic in nature, they cannot statically enforce type constraints on their type arguments,
122+
as this would require down-casting type constraints at runtime, which is not possible in Dart.
123+
124+
If type constraints are required, consider performing runtime checks inside the converter methods.
125+
118126
`NTreeArgConverters` are used to convert complex types that have a fixed number of type arguments.
119127
The consume method is used to expand the stored type arguments to usable generic type arguments
120128
which then need to be used to create a NTreeArgConverter. The `NTreeArgConverter` class provides

0 commit comments

Comments
 (0)