Skip to content

RFC: 'noinfer' Type Operator #122

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

hardlyardi
Copy link

@deviaze
Copy link

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