9 ms·
> source = "date" > source = "produktname" Honestly that doesn't look "completely typesafe": what are those "source"s? Don't they refer to another element? Wh
by bru 9y ago
> source = "date"
> source = "produktname"
Honestly that doesn't look "completely typesafe": what are those "source"s? Don't they refer to another element? What happens if you make a typo there?
- Zolomon 9y agoI wager there is type inference going on and that the IDE will supply red squiggly lines beneath the expression if the author were to supply something that would not one way or the other convert to the types that source can consume.
- cel1ne 9y agoIt maps to database fields. The compiler checks that it's a string, but the rest is done by `admin-on-rest`'s mapping.
- virtualwhys 9y ago> I wager there is type inference going on What will the compiler infer other than a value of type string? > to supply something that would not one way or the other convert to the types that source can consume. Well, clearly `source` takes a string, so it will happily accept "produckname" and blow up at run time. Short of macros I know of no other compile time mechanism that would enable "safe" strings. The usual workaround is to not use plain string values at all and wrap in a sealed type.
- cel1ne 9y agoThis is from the JS-library "admin-on-rest", that I use (via bindings). It's possible to introduce type-safe wrappers here as well.