-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Back type assertion #3186
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
Comments
This is exactly the major problem of current type assertion syntax, and I also feel painful when moving the caret. However, the syntax you suggested may conflict with generics sometimes, e.g.: type Foo = (a: number, b: number)=> number;
var foo = function foo<T>(v: number) { return v * v; };
(<Foo>foo)(1, 3); // OK
foo<Foo>(1, 3); // what does this mean? I suggested foo as Foo .bar as Bar .text and my example can be
However, @CyrusNajmabadi doesn't like the high precedence of |
foo<Foo>(1, 3); // what does this mean? Does it interfere or interplay? You are passing a type arg to a generic. Would it be something difference than to type assert it? |
It depends on the precedence of |
I think I see your point now. I assumed passing in a type on a generic was interchangeable with type asserting it. But your first example clarifies that they aren't. Why is type asserting functions useful? Isn't it more useful to write a new function instead? Then we could just ban type assertions in functions and regard them as generic calls? I like the bracket notation instead of |
I also noticed that it interferes with generic classes as well. My proposal might not be that good. I will keep the issue open for discussion. Because I still see it as a problem to go back-and-fort with the cursor. |
How about just? foo:Foo.bar:Bar.text
f:Foo(1, 2) It's very consistent with the current type definition syntax. |
It seems that TS guys don't like the idea of a type assertion operator with equal or higher precedence than |
Ref #296 |
👍 |
Instead of writing:
We could just write it without going back-and-forth with the cursor:
It is also easier to map the type to each property accessor.
The text was updated successfully, but these errors were encountered: