in rfcs/20210731-tfjs-named-tensors/gtensor.ts [336:359]
public rename<T1 extends DName, T2 extends DName>(
// { [key in G]: T2 }
fromName: G extends T1 ? T1 : never,
toName: T2
// from: { [fromKey in G extends T1 ? T1 : never]: 'from' },
// to: { [toKey in T2]: 'to' },
): GTensor<Exclude<G, T1>|T2> {
// const fromName = Object.keys(from)[0] as string; // T1;
// const toName = Object.keys(to)[0] as ``;
const i = this.dimNames.findIndex(n => (n as DName) === fromName);
if (i === undefined) {
throw new ValueError(`${fromName} is missing from ${this.dimNames}`);
}
// console.log('this.dimNames:', this.dimNames);
// console.log('i:', i);
// console.log('toName:', toName);
const newDimNames = [...this.dimNames] as (Exclude<G, T1>|T2)[];
newDimNames.splice(i, 1, toName);
// console.log('newDimNames:', newDimNames);
return new GTensor<Exclude<G, T1>|T2>(this.tensor, newDimNames);
}