luau-lang / luau

A fast, small, safe, gradually typed embeddable scripting language derived from Lua
https://luau.org
MIT License
4.08k stars 382 forks source link

Types cannot be used before declaration in declaration files (new solver) #1492

Closed checkraisefold closed 2 weeks ago

checkraisefold commented 4 weeks ago

In the following sample, the first argument when connecting the OnServerEvent signal is correctly typed as Player:

declare class Player extends Instance
end

declare class RemoteEvent extends BaseRemoteEvent
    OnClientEvent: RBXScriptSignal<...any>
    OnServerEvent: RBXScriptSignal<(Player, ...any)>
    function FireAllClients(self, ...: any): ()
    function FireClient(self, player: Player, ...: any): ()
    function FireServer(self, ...: any): ()
end

In the following sample, the first argument is an error-type instead:

declare class RemoteEvent extends BaseRemoteEvent
    OnClientEvent: RBXScriptSignal<...any>
    OnServerEvent: RBXScriptSignal<(Player, ...any)>
    function FireAllClients(self, ...: any): ()
    function FireClient(self, player: Player, ...: any): ()
    function FireServer(self, ...: any): ()
end

declare class Player extends Instance
end

This is problematic, because using types before declaration like this was allowed in the old solver and is legal in normal Luau files in the new solver. No solver errors are thrown either, the type is just replaced with an errortype. This holds true for things other than the generic arguments in this example; this happens for normal type refs/properties as welll.