How do i specify keyof
How do i specify Name type so it contains only properties of type number?

86 Replies
i tried to extract but it didnt work
Name extends Extract<keyof WritableInstanceProperties<ConnectedInstance>, number>,
also tried ExtractKeys
can also be done using Pick<>
thanks you but i realised that
keyof WritableInstanceProperties<ConnectedInstance> contains only strings
how can i determine if property have number value or other
where should i put this?
what is this
wherever you want
T can be whatever
but what does it mean?
why it contains strings "T is a number"
it's a conditional type, it checks if T can be assigned to
number, if yes it reuturns the first type, otherwise the second
here the returned types are literal strings, but they can be whatever to fit what you wantim not sure how it would help me making the type of number properties
you asked
how can i determine if property have number value or otherok so
when i do
Name extends WritableInstanceProperties<ConnectedInstance>
how Name type would look? Cuz know i dont really understand
it should be like
["PropName1", "PropName2"...]huh
aa
like
WritableInstanceProperties<ConnectedInstance> returns a type right?yah..
so how it
look
like
you want an array of them?
or maybe
i dont want an array i just want to know what exactly returns this

oh
tysm
now i understand
..why it cant index it?

you forgot keyof before InstanceOfType
InstanceOfType<...> is an Object type
oh yes
but
now theres another error
this is error i was running for using include

same problem now
yo
is there any way to print type
not getting that error on my end
print(typeof Name) would work?
no ... 😅
right its in roblox
how can i see final type then?
types dont exit during run time
hover
oh wait
at runtime
idk
it return very bad type

can you show where the error is
i want like exact values
see in playground
yah you wont get any exact values cause it's a generic
add keyof keyword before
i did and i dont get any errors (other than that related to SeperatedProperty)
lemme see

oh thats because you need an property
replace total.Get() with any number
same error appears
i think that
ts dont understand wat IncludeOfType returns
exactly what WritableInstanceProperty returns, but just property with number values

oh
what
arbitrary type means?youll have to do

uhhh but this is type casting
i can do
as never with the same resulthmm actually lemme try something
k
maybe typescript cant realize that ConnectedInstance[Name] is 100% number because of generics
yah that's exactly the issu
e
yaaah you have to type cast it
idk how else you can fix this
uhhh idk
i dont believe it cant be typed
and dont ever use
as never in scenarios like this, i only use it in places where things should be impossible or there should be an errorikik
thanks you
idk why but when i try to save in terminal it outputs error but vs code dont see an errors


oh i fixed it
so unnecessarily complicated
ExtractKeys<WritableInstanceProperties<T>, number>Missed it in the utility types mb
But you also don't need the keyof
Ohhh i tried to do it first but added keyof
Thanks you
ohh it still shows an error

i cant really give playground cuz it need a property class
cause it's a type that does the same thing as the one i gave you, but it is built in instead of what i gave you
if i add keyof before extract keys it wont work too
right
because
Name: string
switch to Name: Namenooo
Name is
is just a string you passing to constructor
oh
it just name of stat
ye
can u give a playground repro
how can i make link shorter
its too long😃
send as file
@Tverksaac 2.0 faster
i meant send link
as file
heree
@Tverksaac 2.0
yeah i think typescript can't ensure this index in a generic context
never cast is the only way
to go
i tried
or actualy
ConnectedInstance[Name] can be casted but nothing really changes ye
oh ok
thanks you
why tho?
oh nvm
i understood
its same
as ConnectedInstance[Name] but created a type alias so not repeatedyeye
thanks you guys so much❤️
need to pr index type assertion to typescript
so asserts like this:
assert(typeIs(a[b]), "number")
affect the whole scope
not just this one valuewait what
oh your talking about what need to be added?
yeah
oh i see then