Skip to content

Conversation

@hardlyardi
Copy link

@deviaze
Copy link
Contributor

deviaze commented May 6, 2025

We def need this functionality in the new solver, but I think I'd prefer it being a @noinfer attribute instead of an annotation that looks like a type function.

For example (using ariel's example from discord):

local function greedy_insert<V>(tbl: { V }, value: @noinfer V)
  -- ...
end
local a: "a"
local b: "b"
local some_table = { a, b }
local c: "c"
greedy_insert(some_table, c) -- TypeError: Type '"c"' could not be converted into '"a" | "b"'

@daimond113
Copy link

I think using generic constraints once they are implemented instead of adding a separate feature for this will be better. For example, a simple setter function in TypeScript looks like this:

function set<const S, V extends S>(source: S, value: V)

This leverages generic constraints to emulate greediness without requiring a separate feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants