Is it possible to precisely type _.invert in TypeScript?
问题 In lodash, the _.invert function inverts an object's keys and values: var object = { 'a': 'x', 'b': 'y', 'c': 'z' }; _.invert(object); // => { 'x': 'a', 'y': 'b', 'z': 'c' } The lodash typings currently declare this to always return a string → string mapping: _.invert(object); // type is _.Dictionary<string> But sometimes, especially if you're using a const assertion, a more precise type would be appropriate: const o = { a: 'x', b: 'y', } as const; // type is { readonly a: "x"; readonly b: "y