-
Notifications
You must be signed in to change notification settings - Fork 38
expanded version of the optional parameter example #117
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
Conversation
This resolves the concern raised in #111 by being more explicit. For convenience, the specification assumes that undefined is read-only.
|
@ericelliott if it's merged remember to squash it. |
|
Those are not necessarily equivalent. I would assume that if present, an optional param will be of type The difference is subtle, but particularly interesting with named parameter objects: const options = {
foo: undefined,
bar: 'bar'
};
// myFunc({ foo?: String, bar: String }) => NewThing
const resultA = myFunc(options) // Type error. If supplied, `foo` must be a string.
const resultB = myFunc({ bar: 'baz' }); // OK because `foo` isn't supplied.We should address this in the spec, but I'm not sure which way to go on it. Thanks for bringing it up. =) |
|
@ericelliott the default is only used when nothing is passed. Arguments—in contrast with parameters—is what counts in that case. There's no argument when the default is used. There's nothing wrong with my addition in that regard. Your example has nothing to do with my addition. e.g. |
That's not really relevant. The runtime type checker is never going to see the parameter default value. Instead, it's going to essentially do this: if (Object.hasOwnProperty(options.foo)) {
if (isType(options.foo, expectedType)) return true;
return false;
}
return true; |
|
I think we are talking about different things. I am talking about and you are talking about @ericelliott Are you saying that we can't tell the difference between If what you are saying were true it would mean that the type covers the argument and the default which wouldn't let us have a default of a different type than the type declared. @ericelliott Is that what you are scared of? We don't need to set a separate type for the default because it is always implicit since defaults' values are known before hand. |
No, I'm not. Re-read the logic. No, I'm not saying we can't tell the difference between |
|
Ill quote myself because it seems that you have missed my question:
|
|
I am closing this in favor of #118. |
This resolves the concern raised in #111 by being more explicit.
For convenience, the specification assumes that undefined is read-only.