The return type of :FindFirstChild() is incorrect

The return value of :FindFirstChild() should be Instance?, but typechecking is reporting that it is Instance. --!strict is enabled. Correct me if I’m wrong here.

Edit: a nasty side effect of this is I cannot downcast to Folder?. I have to first cast to any which is pretty nasty
i.e: local leaderstats = (player:FindFirstChild("leaderstats")::any)::Folder?

2 Likes

For a workaround you can do this for now until it’s fixed:
Example: local diamonds: IntValue? = <code> :: IntValue

Cheers fellow type checker.

1 Like

Thanks for the report! We’ll follow up when we have an update for you.

Hello.

This is a decision we made to balance false positive error reports in the current system we have set up.
We might change our decision when additional type inference improvements are completed, but for now we are not ready to switch T over to T? for FindFirstChild.

Maybe as a short-term solution, it will be better for us to make Base → Derived? cast work.

1 Like

Base → Derived? would be a wonderful addition

1 Like