Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spread arguments #238

Closed
RyanCavanaugh opened this issue Jul 24, 2014 · 1 comment
Closed

Spread arguments #238

RyanCavanaugh opened this issue Jul 24, 2014 · 1 comment
Labels
Committed The team has roadmapped this issue ES6 Relates to the ES6 Spec Suggestion An idea for TypeScript

Comments

@RyanCavanaugh
Copy link
Member

Example

f(1, 2, ...items, 3, ...more)

Codegen

f(...items); // ... becomes...
f.apply(void 0, items);  // strict mode.  Otherwise, 'this'

obj.foo(...items); // ... becomes...
obj.foo.apply(obj, items); // , but only want to evaluate obj once, so we inject an:
function __apply(obj, method, args) {
    obj[method].apply(obj, args);
}
__apply(obj, "foo", items);

CoffeeScript introduces a fresh var, hoists it to top, and uses it to prevent re-eval of 'obj'. Local vars could be done inline

Typecheck

f(1, 2, ...items, 3, ...more) : f ( T, T, BCT (...items, 3, ...more));

Issue is that this would prevent potentially valid code from passing typecheck.  Key idea is that we would be checking the arity that we know as well as the BCT, knowing that the spread arrays could be empty.

Questions

Do we want to be able to spread array-like, like the array-like objects that come from the DOM? If we do, we could use the CoffeeScript approach. We could tell arrays and array-like apart statically in the type system.

@DickvdBrink
Copy link
Contributor

Seems to be fixed with #1931

@danquirk danquirk added Committed The team has roadmapped this issue and removed Needs More Info The issue still hasn't been fully clarified labels Mar 10, 2015
@microsoft microsoft locked and limited conversation to collaborators Jun 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Committed The team has roadmapped this issue ES6 Relates to the ES6 Spec Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

3 participants