@rbxts/jsnatives



Object.excludeTypes

Removes properties of specified types from the input object.

Signature

function excludeTypes<T, Deep extends boolean>(
obj: T,
types: (keyof CheckableTypes)[] | Set<keyof CheckableTypes>,
deep?: Deep
): Deep extends true ? DeepPartial<T> : Partial<T>

Description

The Object.excludeTypes() method removes properties of specified types from the input object. This is useful for filtering out specific types of values from an object, such as functions. The operation modifies the input object directly.

Examples

Basic type exclusion

const obj = {
name: "John",
age: 30,
sayHello: () => print("Hello"),
};
// Exclude functions
Object.excludeTypes(obj, ["function"]);
print(obj); // { name: "John", age: 30 }

Deep type exclusion

const obj = {
user: {
name: "John",
age: 30,
sayHello: () => print("Hello"),
},
metadata: {
timestamp: Date.now(),
getValue: () => "value"
}
};
// Exclude functions recursively
Object.excludeTypes(obj, ["function"], true);
print(obj); // { user: { name: "John", age: 30 }, metadata: { timestamp: 1234567890 } }

Notes