4 ms·
Typescript has massively improved my quality of life working on JS projects. I occasionally run into constructs that are difficult to type but most of the time
by cageface 7y ago
Typescript has massively improved my quality of life working on JS projects. I occasionally run into constructs that are difficult to type but most of the time TS just works. Thanks to all the people behind this project for all your work!
- MuffinFlavored 7y agointerface 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).