4 ms·
> eg a function that can return several types of objects, I had to put the return type of the function to any to have it compiled Typescript 1.4 to the rescue
by Eridrus 11y ago
> eg a function that can return several types of objects, I had to put the return type of the function to any to have it compiled
Typescript 1.4 to the rescue with union types!
Though I would argue that if this is code you're writing yourself, a function that returns multiple types is bad design. Though given the prevalence of different types for different strings, the way they've typed things like addEventListener is interesting.
- Keats 11y agoIt actually didn't work with 1.5 beta, can't remember the exact failure. This function actually returns an object depending on the single param, an enum member. All the objects are extending a main type with a couples different properties on each, it's cleaner than having a switch everywhere i want to instantiate one ofthose