I am working with a specialized string type called
MyType = string & { __brand: 'mytype' }
.
Is there a way to define an override for the Array.join
method specifically for arrays of type Array<MyType>
so that it returns MyType
instead of string
?
Additionally, I would like the solution to be generic and capable of handling any type that extends, such as Mergeable
, allowing it to join and create a new instance of itself.
type Mergeable = string & { __mergeable: true }
type MyType = Mergeable & { __brand: 'MyType' }
const arr: MyType[] = ['a', 'b', 'c'] as any
const merged: MyType = arr.join(', ' as MyType)