Remix.run Logo
▲ monster_truck 7 hours ago

It's had return type declarations since 7. There's even intersection and literal types now. You could have typed this into google and it would have told you

▲origini 6 hours ago | parent | next [-]

I did and it told me that it doesn't support typed arrays.

▲bakugo 6 hours ago | parent | prev [-]

Type declarations are still quite limited, though. For example, you can declare that a function returns an array or a string, but not an array of strings.

▲lofaszvanitt 5 hours ago | parent [-]

Use a class if you need them.

▲bakugo 5 hours ago | parent [-]

How does that solve the problem? You can't declare an array of strings inside a class, either.

▲eithed 2 hours ago | parent | next [-]

You can annotate the method as `@return array<array-key,string>` or even `@return list<string>` (array of strings = indexed via anything that can be used as a key in PHP vs list of strings = indexed via incrementing integers, starting from 0). I guess the OP suggestion was to use Arrayable / Iterable interfaces, which would work as well, but would require more effort (= yes, declare a class)

▲lofaszvanitt 4 hours ago | parent | prev [-]

Do some research :D.

▲origini 4 hours ago | parent [-]

Just to be clear, you suggest to wrap a typed array into its own class? is that the suggestion you think of?

Because if yes, thats just ugly and a hack/workaround.