Union Collection types for typescript transform #703
-
In a data class, I have a collection defined as follows: /** @var Collection<int, WorktimeEntry|WorktimeEntryHourly> */
readonly public Collection $entries; In version 3 of this package, it was possible to transform this correctly to TypeScript. However, in version 4, plain collections are now supported, causing the union type to be ignored in TypeScript, resulting in only Array being typed. Would it be possible to allow union types in the typescript transformer like in the last version? I managed to pinpoint the stripping of the union type to https://github.com/spatie/laravel-data/blob/main/src/Support/Annotations/DataIterableAnnotationReader.php#L145 I solved it using the following commit: Sparclex@4c9cea4 but it is only a hacky solution. Would be great if there is an official one. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I agree with what you're saying, but atm I'm not going to change data to only support multiple types in TypeScript since that would be only half (probably 1/20) of the work required. When we start supporting multiple types let's do it good from the start. There's probably a quicker fix in the near future, I'm working on TypeScript transformer 3 which doesn't use data anymore for these kinds of constructs so it would transform the types correctly. |
Beta Was this translation helpful? Give feedback.
I agree with what you're saying, but atm I'm not going to change data to only support multiple types in TypeScript since that would be only half (probably 1/20) of the work required. When we start supporting multiple types let's do it good from the start.
There's probably a quicker fix in the near future, I'm working on TypeScript transformer 3 which doesn't use data anymore for these kinds of constructs so it would transform the types correctly.