centau / vide

A reactive Luau library for creating UI.
https://centau.github.io/vide/
MIT License
74 stars 16 forks source link

Fix source type #27

Closed Ketasaja closed 1 month ago

Ketasaja commented 1 month ago

Before, only one error with strict typing:

local s = vide.source("")
s(0)
s({})
s("")
s(true)
local u: vide.Source<string> = vide.source({})
u("")
u(0) -- TypeError: Type 'number' could not be converted into 'string'
local v = vide.source()
v(0)
local w: vide.Source<number | string> = vide.source()
w("")
w(0)

After, many errors with strict typing:

local s = vide.source("")
s(0) -- TypeError: Type 'number' could not be converted into 'string'
s({}) -- TypeError: Type '{  }' could not be converted into 'string'
s("")
s(true) -- TypeError: Type 'boolean' could not be converted into 'string'
local u: vide.Source<string> = vide.source({}) -- long error
u("")
u(0) -- TypeError: Type 'number' could not be converted into 'string'
local v = vide.source()
v(0)
local w: vide.Source<number | string> = vide.source()
w("")
w(0)
centau commented 1 month ago

On my machine the current source type produces the same errors shown in your second example with the latest version of luau-lsp. Did you definitely test it in strict mode?

Ketasaja commented 1 month ago

This is Luau-LSP 1.32.1 freshly installed. When I make a new project I do get errors, but even after wally installing again or copying Vide from the new project, my existing project still doesn't get errors without the change.

I'll try to minimal reproduce this. I'd be surprised if I ran into a limit on such a small project. vide 1 vide 2

Ketasaja commented 1 month ago

@centau I figured out the new project had a .luaurc in the root folder with "languageMode": "strict", while in my existing project it was only for my code, not for the packages directory.

Adding --!strict to Vide's main module fixed this, but that would cause new errors for nonstrict users, so maybe there's no good way to make this change.

I think strict calling into nonstrict is supposed to error, but that might be a Luau issue.