GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||
GeezerVison is showing github.com — add compiler flag to enable granular inference outside var/let by KiaraGrouwstra · Pull Request #17785 · microsoft/TypeScript Conversation
|
|
Question: does this affect either of theses? If so, you'll need to add a special case to allow them, or you'll need an ungodly number of casts for things like options objects, etc. interface SomeInterface { a: boolean } declare function foo(arg: number[]): void declare function bar(arg: SomeInterface): void // As variable assignees const a: number[] = [1, 2, 3]; const b: SomeInterface = {a: true}; // Same, but as arguments foo([1, 2, 3]); bar({a: true}); |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
@isiahmeadows: // @widenTypes: false interface SomeInterface { a: boolean } declare function foo(arg: number[]): void declare function bar(arg: SomeInterface): void // As variable assignees const a: number[] = [1, 2, 3]; // number[] const b: SomeInterface = {a: true}; // SomeInterface // Same, but as arguments foo([1, 2, 3]); // ok, tuple assignable to array bar({a: true}); // ok, assignable
I thought of still typing
I'm kinda neutral there, I presume things will gravitate toward option 1.
Well, Edit: updated. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
4bea1a9 to
601f5f2
Compare
There was an error while loading. Please reload this page.
|
Okay, got parameters down too. Now, this was dubbed a huge / massive breaking change, so... what's the damage?
That's it; couple dozen casts on a humongous code-base. So the good news is, this doesn't even depend on #17765; it seems good now. I'm ready for feedback. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
7b9bf2c to
c85ba7b
Compare
|
This looks great! I am constantly annoyed by the fact that TypeScript doesn't always infer the most specific type. Is anyone taking a look at this PR? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I came here looking for a "noImplicitWidening" option to disable all, well, implicit type widening. Is this PR an implementation of that? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
John Nilsson (@JohnNilsson): pretty much. The exception here is the right-hand side of (Explicit annotations like |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
John Nilsson (@JohnNilsson) same, I just want a flag to disable type widening everywhere. If I ever need to widen a tuple to an array I’m fine with doing that via a manual cast. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Any updates on this? Is this PR blocked on something, or can we make a yes/no call on whether this can make it in? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I do not think this is a direction we are willing to peruse at the time being. First, we really do not want flags that change type system behavior since that effectively creates dialects of the language; the ones we have allowed in the past fall into one of two categories, 1. temporary patches for breaking changes behavior (e.g. Second, overloading the meaning of const is not something we are crazy about. we have done something similar with function parameters, but do not think we want to sanction this meaning of const declarations. Sorry for the delay. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Mohamed Hegazy (@mhegazy) is the TypeScript team thinking about how to solve the usability issues around type widening? In my mind and I think a lot of others it is the biggest wart on the language currently. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Yes, and we continue to think of ways to alleviate these pains. One thing to note is it took us a few iterations to get where we are now. and there are many scenarios on both sides of any change at this point that would break. we try to balance all these as we introduce changes. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thanks for the response. fwiw, I used the flag figuring this fell under # 2 -- stricter, (imo) preferable, some (imo minor) migration. I'd prefer not needing flags as well. The semantic overloading of |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.