export interface SomeShape { b: string, c: string, a: string, } // Specify your sort order here const rank: Array = ['a', 'b', 'c']; export function sortedKvpString(obj: SomeShape) { return Object.entries(obj) .sort(([a_], [b_]) => { const a = a_ as keyof SomeShape; // #ts workaround :.( const b = b_ as keyof SomeShape; return rank.indexOf(a) - rank.indexOf(b); }) .map(([key, val])=> `* ${key}: ${val}`) .join('\n'); } // Now we know they'll print in order: console.log( sortedKvpString({b: 3, a: 1, c: 5}) // prints a,b,c );