Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // this will currently compile
- export const foo1 = function(symbols: any, v?: boolean){ // symbols is an optional Array<Symbol> argument
- if(arguments.length < 2){
- v = symbols;
- symbols = [];
- }
- const tags = {};
- for(let s of symbols){
- tags[s] = true;
- }
- return {
- value: v,
- tags
- }
- };
- // now this could be made so much simpler with some compiler tricks!
- // but this won't currently compile
- export const foo2 = function(...symbols: Array<Symbol>, v: any){
- const tags = {};
- for(let s of symbols){
- tags[s] = true;
- }
- return {
- value: v,
- tags
- }
- };
- // in the second case, I don't have to check to see if the array exists
- // and I no longer need optional paramaters
- // so before, it looks like this:
- foo1([Symbol('one'), Symbol('two')], {
- });
- // now it looks like:
- foo2(Symbol('one'), Symbol('two'), {
- });
Add Comment
Please, Sign In to add comment