Constraints on interface members in typescript generics
I have a method, that should accepts any object, as long as all its fields are strings or numbers I made this, which works great with duck typing static interpolateParams( route: string, params: {[key: string] : string | number}) : string { const parts = route .split("/") .map(part => { const match = part.match(/:([a-zA-Z09]*)\??/); if (match) { if (!params[match[1]]) { console.error("route argument was not provided", route, match[1]); return part; } return params[match[1]]; } else { return part; } }) return "/" + parts.slice(1).join("/"); } and call interpolateParams("/api/:method/:value",