Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion include/customDefinitions.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>;
CreateCollection<S extends string>(
this: CollectionService,
query: Selector.ValidateSelector<S> extends S ? S : Selector.ValidateSelector<S>,
root?: Instance,
): Collection<Selector.Solve<S>>;
}

interface CompressorSoundEffect extends SoundEffect {
Expand Down Expand Up @@ -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,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The space of the return values and the relativity of the motion are determined by the DragSpace and DragRelativity properties, unless overridden by returning a specified Enum.UIDragDetectorDragRelativity and Enum.UIDragDetectorDragSpace as the third and fourth return values.

Based on the docs, sounds like we need the tuple to possible supply an optional Enum.UIDragDetectorDragRelativity and Enum.UIDragDetectorDragSpace.

Is this rotation value optional?

): void;
}

/** @client */
Expand Down
5 changes: 4 additions & 1 deletion include/generated/None.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
40 changes: 35 additions & 5 deletions include/roblox.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1890,7 +1890,7 @@ interface FontConstructor {
declare const Font: FontConstructor;

// InstanceHandle
interface InstanceHandle {
interface InstanceHandle<T extends Instance = Instance> {
/**
* **DO NOT USE!**
*
Expand All @@ -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>): T | undefined;
Wait(this: InstanceHandle<T>): T;
Wait(this: InstanceHandle<T>, timeout: number): T | undefined;
}
interface InstanceHandleConstructor {
new (instance: Instance | undefined): InstanceHandle;
new <T extends Instance>(instance: T | undefined): InstanceHandle<T>;
}
declare const InstanceHandle: InstanceHandleConstructor;

Expand Down Expand Up @@ -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 Instance> = T extends unknown
? {
[K in keyof T]: T[K] extends RBXScriptSignal ? K : never;
}[keyof T]
: never;

type CollectionSignalArguments<T extends Instance, K extends string> = T extends unknown
? K extends keyof T
? T[K] extends RBXScriptSignal<infer SignalCallback extends Callback>
? Parameters<SignalCallback>
: never
: never
: never;

type CollectionSignalCallbacks<T extends Instance> = {
[K in CollectionSignalKeys<T> & string as `On${K}`]?: (
instance: T,
...args: CollectionSignalArguments<T, K>
) => void;
};

type Collection<T extends Instance = Instance> = CollectionSignalCallbacks<T> & {
Enabled: boolean;

OnAdded?: (item: T) => void;
OnRemoved?: (item: T) => void;
ForEach(this: Collection<T>, callback: (item: T) => void): void;
Destroy(this: Collection<T>): void;
};
24 changes: 24 additions & 0 deletions tests/collection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/// <reference path="../include/roblox.d.ts" />

declare const partCollection: Collection<Part>;

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 = () => {};
Loading