Assign business type from method call (removing dupes)

After adding a new entry, I want to check and remove duplicates from the list of things that have been added. So on the Add Field/added attribute, I call a method to simply remove any duplicates:

function removeDups<T>(array: T[]): T[] {
	return [...new Set(array)];
}
// this.aliases = removeDups(this.aliases);

The assignment (commented out) is of type Alias array (a business object)…so the question is, how do I case the returned array back to the business object type?

The removeDups function that you have there is pure TypeScript. It returns an array of objects but not an ApexDataArray (or ApexFormArray).

Assuming that this.aliases is an ApexFormArray, you may be able to do something like this:

this.aliases = new AliasFormArray(removeDups(this.aliases);

Remember that you may need to check a property for uniqueness vs the whole object. Let’s assume you want them unique by name.