3 ms·
interface IntMap { [name: string]: int } interface StringMap { [name: string]: string } I really feel something like that should c
by MuffinFlavored 7y ago
interface IntMap {
[name: string]: int
}
interface StringMap {
[name: string]: string
}
I really feel something like that should come standard so I didn't have to rewrite it so many times when coding in the wild.
- AaronFriel 7y agoThese are: type IntMap = Record<string, int>; type StringMap = Record<string, string>;
- nojvek 7y agoYou can always make a generic Interface ObjMap<T> = {[name: string]: T} And the use it as const intMap: ObjMap<int> and voila!
- WorldMaker 7y agoIf you get a chance, you should also consider moving more towards ES2015 Map<K, V> and Set<V> objects instead of object literals as property maps. Browser support for Map/Set is pretty universal at this point (and easy to polyfill in the worst case that you need to support IE <= 10, which why?). You get better performance in some cases, and better handling of edge cases (strange string keys, accidental prototype inheritance, key name / language keyword clashes).