The typestate and type refinement improvements mentioned in the original post should support early return like in your example. I’m not entirely sure about the underlying cause of the clone one, so it might be a legitimate warning (can the clone fail?), it might be a bug fixed in the new solver, or it might be a bug that is not fixed yet. Feel free to try it out and report back!
I think that’s a bug.
I think your "Coins"
converted into a string
instead of remaining a FreeType
like so ("Coins" <: 'a <: string)
something like that.
This is the sort of knowledge I’ve obtained after a few days looking at the Source Code. But I yet need to learn more, maybe.
This screenshot is actually good because it has the full code to re-produce the issue.
For some reason, replacing
type Keys = keyof<typeof(PlayerData)>
with
type Keys = index<typeof(PlayerData), keyof<typeof(PlayerData)>>
immediately crashes studio.
as well, we need valueof too!
with keyof (and rawkeyof) we can make a type with the string keys in the table.
what about the same thing with valueof and arrays? Here some code to explain this:
export type Enumerator<List> = Object.Object & { [List]: number }
local function new<V>(enumList: V): Enumerator<valueof<V>>
local inverse = {}
for k, i in enumList do
inverse[i] = k
end
return setmetatable(enumList, { __index = inverse, })
end
local EmitType = new({
"Position",
"SetInWorld",
"Destroyed",
})
EmitType.Position -- 1 with autocomplete thats better.
EmitType[1] -- "Position"
with this we can make a Enumerator TypeScript like, it allow you to inverse your enums like this
enum EmitType { // i got it from my code
"Position",
"SetInWorld",
"Destroyed",
}
EmitBlockType.Position // 0
EmitBlockType[0] // "Position"
I noticed something with the example bar() function in the Nonstrict section:
Wouldn’t if math.random() then...
always return true, since math.random()
returns a number?
Great update! Would love to see generic type support for type functions though (eg. <A>(Property : A & keyof<ClassType>, PropertyValue : index<ClassType, A>) -> ()
) or something similar.
Im also getting issues with refining the string
type to a string literal (eg. "something" | "somethingElse"
)
Very exciting changes! However – I accepted the beta feature and my Studio memory shot to 50gb (yes, gb.) and then crashed. I turned the beta feature off, restarted, and now my standard type checking doesn’t work at all
You should just be typing children
as {Part}
and/or the return type of the function as {Part}
Based on the code sample, that wouldn’t be scalable since the function’s return changes based on what’s provided as the className
argument. Typing parts
to {Part}
would be better
I misunderstood what he was wanting which I get now. He could try something with generic typings to get the expected result.
index
and rawget
are probably what you’re imagining valueof
would do.
This will probably look something like <A: keyof<ClassType>(A, index<ClassType, A>) -> ()
, and the feature you’re asking for is called bounded generics which I already said further up in the thread in response to Dekkonot that it is planned.
Frankly, it depends a lot on what your code looks like whether the new solver is readily-adoptable or needs a lot of work, and a large part of the reason we’re doing the beta now is to identify issues with idiomatic code in the various styles that are used by developers on Roblox. There’s plenty of ways of writing code for the new type solver right now that don’t have issues, but discovering issues that pertain to the styles you all choose to write code in is a lot easier if you can try it out and point things out that don’t make sense!
Type functions
I saw the RFC for this but when I turned on the flag for it, it just said “syntax not supported”. give me some pointers?
Can we have a class name type? It would allow for autocompletion like Instance:IsA()
or Instance.new()
Something like this maybe?
or even
type functions aren’t done yet, the rfc’s been merged but they haven’t been implemented yet
value of already exists! its just index<>
that wont work because instance is just the type for the base instance class, adding a type function to roblox for instance names and property tables has been discussed before but nothings here yet
how are you typing your requires? are you using a custom require?