-
Notifications
You must be signed in to change notification settings - Fork 338
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
Type 'T' could not be converted into 'T' #1256
Comments
In your case, all of these are equivalent: -- case 1
asd(function<boolean>(Toggled: boolean)
BoolValue(Toggled)
end)
-- case 2
asd(function<T>(Toggled: T)
BoolValue(Toggled)
end)
-- case 3
local function callback<T>(Toggled: T)
BoolValue(Toggled)
end
asd(callback) This would be a good counterexample: asd(function<{ x: number }>(Toggled) -- SyntaxError: Expected identifier, got '{'
print(Toggled)
end) In case 1, the type in the angle brackets is not referring to the concrete type The best workaround I can think of is moving the type parameter to --!strict
type Callback<T> = (Toggled: T) -> ()
local function asd<T>(Callback: Callback<T>, Value: T)
Callback(Value)
end
local BoolValue: (boolean) -> () = print
local NumberValue: (number) -> () = print
asd(BoolValue, true)
asd(NumberValue, 1) It would probably be a good idea to "reserve" existing types from type parameters so they can't be confused. |
Since this is user error, I'm going to close out this issue. You can open a new issue if you want to suggest some particular behavior for naming a generic the same thing as a primitive type, but the type error in this case is right. |
Ah! thank you, thats my fault for the misunderstanding |
With the code below in strict mode an error is prompted "Type 'T' could not be converted into 'T'". Im able to replicate this issue multiple times:
Example 1 using
T
asboolean
:Example 2 using
number
asT
generic:Workarounds? Change the required function argument type of
BoolValue
toany
:The text was updated successfully, but these errors were encountered: