diff --git a/include/customDefinitions.d.ts b/include/customDefinitions.d.ts index 55dd19fb5..dd734cfa5 100644 --- a/include/customDefinitions.d.ts +++ b/include/customDefinitions.d.ts @@ -240,6 +240,11 @@ interface CollectionService extends Instance { RemoveTag(this: CollectionService, instance: Instance, tag: string): void; RemoveTag(this: Instance, tag: string): void; GetAllTags(this: CollectionService): Array; + CreateCollection( + this: CollectionService, + query: Selector.ValidateSelector extends S ? S : Selector.ValidateSelector, + root?: Instance, + ): Collection>; } interface CompressorSoundEffect extends SoundEffect { @@ -1176,7 +1181,10 @@ interface UIDragDetector extends UIComponent { proposedRotation: number, ) => LuaTuple<[UDim2, number, Enum.UIDragDetectorDragRelativity?, Enum.UIDragDetectorDragSpace?]>, ): RBXScriptConnection; - SetDragStyleFunction(this: UIDragDetector, callback: (inputPosition: UDim2) => UDim2 | void): void; + SetDragStyleFunction( + this: UIDragDetector, + callback: (inputPosition: Vector2) => LuaTuple<[UDim2, number]> | UDim2 | void, + ): void; } /** @client */ diff --git a/include/generated/None.d.ts b/include/generated/None.d.ts index 46a1f9343..6cda869f1 100644 --- a/include/generated/None.d.ts +++ b/include/generated/None.d.ts @@ -51455,7 +51455,10 @@ interface UIDragDetector extends UIComponent { * @param this Instance which facilitates and encourages interaction with UI elements in an experience. * @param function Function for monitoring `DragContinue` signals. This function receives the signal's screen space input position and returns a `UDim2` and float containing the desired motion of the drag in the desired space and relativity. If this function returns `nil`, the object will not be moved. */ - SetDragStyleFunction(this: UIDragDetector, callback: (inputPosition: UDim2) => UDim2 | void): void; + SetDragStyleFunction(this: UIDragDetector, callback: (inputPosition: Vector2) => LuaTuple<[ + UDim2, + number + ]> | UDim2 | void): void; /** * Fires when a user continues dragging the UI element after `DragStart` has been initiated. * diff --git a/include/roblox.d.ts b/include/roblox.d.ts index c02e03477..59eb7fbbd 100644 --- a/include/roblox.d.ts +++ b/include/roblox.d.ts @@ -1890,7 +1890,7 @@ interface FontConstructor { declare const Font: FontConstructor; // InstanceHandle -interface InstanceHandle { +interface InstanceHandle { /** * **DO NOT USE!** * @@ -1899,12 +1899,12 @@ interface InstanceHandle { * @deprecated */ readonly _nominal_InstanceHandle: unique symbol; - Get(this: InstanceHandle): Instance | undefined; - Wait(this: InstanceHandle): Instance; - Wait(this: InstanceHandle, timeout: number): Instance | undefined; + Get(this: InstanceHandle): T | undefined; + Wait(this: InstanceHandle): T; + Wait(this: InstanceHandle, timeout: number): T | undefined; } interface InstanceHandleConstructor { - new (instance: Instance | undefined): InstanceHandle; + new (instance: T | undefined): InstanceHandle; } declare const InstanceHandle: InstanceHandleConstructor; @@ -3523,3 +3523,33 @@ interface CreateMeshPartAsyncOptions { /** The value of `FluidFidelity` in the resulting part. Defaults to `Enum.FluidFidelity.Automatic` if the option is absent or the `options` table is `nil`. */ FluidFidelity?: Enum.FluidFidelity; } + +type CollectionSignalKeys = T extends unknown + ? { + [K in keyof T]: T[K] extends RBXScriptSignal ? K : never; + }[keyof T] + : never; + +type CollectionSignalArguments = T extends unknown + ? K extends keyof T + ? T[K] extends RBXScriptSignal + ? Parameters + : never + : never + : never; + +type CollectionSignalCallbacks = { + [K in CollectionSignalKeys & string as `On${K}`]?: ( + instance: T, + ...args: CollectionSignalArguments + ) => void; +}; + +type Collection = CollectionSignalCallbacks & { + Enabled: boolean; + + OnAdded?: (item: T) => void; + OnRemoved?: (item: T) => void; + ForEach(this: Collection, callback: (item: T) => void): void; + Destroy(this: Collection): void; +}; diff --git a/tests/collection.ts b/tests/collection.ts new file mode 100644 index 000000000..48f4db4f8 --- /dev/null +++ b/tests/collection.ts @@ -0,0 +1,24 @@ +/// + +declare const partCollection: Collection; + +partCollection.OnTouched = (part, otherPart) => { + const typedPart: Part = part; + const typedOtherPart: BasePart = otherPart; +}; + +partCollection.OnAdded = part => { + const typedPart: Part = part; +}; + +partCollection.ForEach(part => { + const typedPart: Part = part; +}); + +// @ts-expect-error +partCollection.OnTouched?.Connect(() => {}); + +declare const instanceCollection: Collection; + +// @ts-expect-error +instanceCollection.OnTouched = () => {};