How can I set properties by a given table of properties

This might be a dumb question but Im new on roblox-ts, so, I basically have this function that creates a new roblox object and additionally, you are able to give a table of properties to set with the structure: {propertyName = propertyValue} example New("Blur", {Size = 10},Camera) AllProperties type is defined as:
type AllProperties = CreatableInstances[keyof CreatableInstances];
type AllProperties = CreatableInstances[keyof CreatableInstances];
I ran out of ideas, this stills red, if you can also explain me a little I would appreciate it a lot here's a playground https://roblox-ts.com/playground/#code/C4TwDgpgBAggNnACgJwPaWcAlhAzlAXigGFkIBDYcgIzggEkA7XKxgYzwG0BrCEVAGYkylGnSYty7PAF0AUHIEBXdtlSMoAOQgB3ABRs45XLk3kAthABcUXvyGkKVWg2asOuADRQwaDNjwAfhsAbygePhs7QVgEFHQITBxcGRsVbkZUHUYAX28wcjJGYGCoCXcIAEobcqkOKBC5AEg2dRYoRl1a6UIO3TK3OogDIxMzS08CouBKgG5mpqwhPV8EpLxKhoWmgVRkKAM24HDV-xBx6Hy-RNAANXI4JQgZKBiCrGRcFev13ErNxpNIFNMBsB5wPR6TYEAB8W2BTU6Om6HE4pxu5ws0GMtj4MXgSB+ARSvXRmBA90eEG2OTmCxyzQZTTIwCUyA0SJREHmOSAA
No description
22 Replies
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
PepeElToro41
PepeElToro41OP•2y ago
@Noire ā˜• @Dionysusnu so, I somehow managed to set the type for the properties table, it has correct autocompletition, most of that mess for properties type was because I got crazy trying a bunch of things but still telling me that last error
No description
PepeElToro41
PepeElToro41OP•2y ago
this works fine
No description
PepeElToro41
PepeElToro41OP•2y ago
this is the error
No description
PepeElToro41
PepeElToro41OP•2y ago
also that's how I defied those types
type PropertiesTable<T extends Instance> = Partial<WritableInstanceProperties<T>>;
type Write<T> = WritablePropertyNames<T>;
type PropertiesTable<T extends Instance> = Partial<WritableInstanceProperties<T>>;
type Write<T> = WritablePropertyNames<T>;
PepeElToro41
PepeElToro41OP•2y ago
found the solution of adding as never at the end, I guess there's no way to set it with correct types thanks :DD
PepeElToro41
PepeElToro41OP•2y ago
yeah I always try to typecheck and workaround with another way, but Im pretty happy with this autocompletition tho, I started liking ts
No description
roblox-ts
roblox-ts•2y ago
Playground link
Posted by <@214262712753061889>
roblox-ts
roblox-ts•2y ago
Playground link
Posted by <@214262712753061889>
Fireboltofdeath
Fireboltofdeath•2y ago
Im not home right now so I can't take a look but I have noticed typescript has a tendency to cut off conditionals where the generic is in a check type you're iterating over PairsResult<typeof properties> not the a type you're checking that it's not undefined casting uses inference, type aliases do not as for why this is returning [unknown, unknown] it's because TypeScript is widening to the most possible type first element gets unknown from [unknown, defined], second element gets it from Exclude<V, undefined> in ReadonlyArray and ReadonlyMap V can be anything, so its constraint is unknown nothing comes to mind besides overloading, of course, but I don't think that'd be ideal Ah! well, pairs doesn't quite work either in that case its fallback still performs a conditional so the code won't know the correct type the keyof T extends never special case, not sure its purpose mmm I wonder if the switch from defined -> unknown would be particularly breaking assuming that's the only difference between your implementation and the overloads it can't, Exclude uses a conditional NonNullable might, though it uses an intersection yeah, NonNullable works
Fireboltofdeath
Fireboltofdeath•2y ago
it infers [unknown, defined] by doing the keyof T extends never check on the first overload so it'll fall over to the second overload for generics
roblox-ts
roblox-ts•2y ago
Playground link
Posted by <@214262712753061889>
Fireboltofdeath
Fireboltofdeath•2y ago
mmm TypeScript isn't able to do assignments like that with plain destructuring, but the generic one probably preserves the relationship the static one will become "a" | "b", obj["a" | "b"] whereas the generic one will become K, V[K]
roblox-ts
roblox-ts•2y ago
Playground link
Posted by <@214262712753061889>
Fireboltofdeath
Fireboltofdeath•2y ago
having conditional pairs as a overload after readonlyset/readonlymap/etc special cases might work? unions I think current pairs will fail on generics with a union constraint, so it should be fine if the conditional fallback does as well that leaves known unions which would now iterate correctly using the conditional fallback sorry, what's this showing?
roblox-ts
roblox-ts•2y ago
Playground link
Posted by <@214262712753061889>
Fireboltofdeath
Fireboltofdeath•2y ago
you're intersecting the tuple
roblox-ts
roblox-ts•2y ago
Playground link
Posted by <@259237045593964554>
roblox-ts
roblox-ts•2y ago
Playground link
Posted by <@214262712753061889>

Did you find this page helpful?