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 — Weak type detection by sandersn · Pull Request #16047 · microsoft/TypeScript Conversation
|
|
The Travis failure occurs because of an error in react.d.ts, which our tests have a copy of. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Where's the head-desk emoji when you need it |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
This even includes react.d.ts itself!
|
The weird test changes in controlFlowInstanceOf, subTypeReduction* and generatorTypeCheck63 are because subtype reduction has changed. So unions produce a different type when asked to do subtype reduction: { foo?: Foo } | { bar: Bar } // used to reduce to { foo?: Foo } // now it does not! I don't think it was supposed to work this way according to the spec, so this is an improvement. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| result &= related; | ||
| } | ||
| dynamicDisableWeakTypeErrors = saveDynamicDisableWeakTypeErrors; | ||
| if (source !== globalObjectType && getPropertiesOfType(source).length > 0 && every(target.types, isWeak)) { |
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Comment on what you're doing here and below - the intent is obvious now, but it won't be to a random team member in 3 months. 😄
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I refactored this into a separate function and a named boolean. I think the two new names should serve as adequate documentation.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Summary of Real World Code runThere aren't as many errors as I thought -- 9, after the React fix in DefinitelyTyped. They are all very good errors except one questionable I will look at the errors from DefinitelyTyped next. GoodMisleading namesThere are two kinds of misleading names:
These are really hard to catch without the aid of a compiler. And Typescript wasn't checking assignability at all for weak targets. Now it catches the most egregious errors. This change found one instance of wishful thinking in VS Code and one instance of the namespace problem in another internal Microsoft project. (Who else would have four layers of legacy controls? (Don't answer that.)) Confusing typesThere are plenty of types which aren't assignable but look like they might be at first glance. For example: The compiler now catches more of these. It found 2 in VS Code, and 2 in 2 other internal Microsoft projects. Misleading
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Summary of DefinitelyTyped runAgain, there are not as many errors as I thought. Of 3095 projects total, there were 20 errors in definition files and about 80 errors in test files. I haven't looked at the test files yet, but I didn't find any new error patterns in the definitions. Here's the breakdown: GoodMisleading namesWishful thinking: kendo-ui (3 times), react-leaflet, react-native Misleading
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Fantastic. Those are much better results than I expected 👍 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Yes, there are few enough errors that I am going to go fix up DefinitelyTyped right now. Note that the Ugly error pattern is very similar to one in the compiler I had to fix in this PR. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
This changes the definition of weak types
Previously, intersections disabled the weak type check for their constituents, and all properties (recursively) of their constituents. Also add test for this case.
|
What is the canonical recommended way of solving React-like false error? I.E. base class with all methods optional, derived class doesn't implement any of those optional methods. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
mihailik class-interface merging. Remove the implements clause from the class declaration and add a line preceding it: interface C extends Optional {} |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
So I thought this would get resolved upstream in I don't really want to wait a month for this, so I'm trying to figure out a way to deal with this in the meantime. What I don't understand about this How does casting help me. This is an error in the typings themselves, not in my code. I'm guessing that in order to get this to compile, I'm going to have to go in and modify |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
This is actually a problem with |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
DefinitelyTyped/DefinitelyTyped#17581 will almost fix this. Unfortunately, the improved types expose another bug in This is a much simpler fix, though. I'll update palantir/blueprint#1237. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Shouldn't this also prevent passing primitives as a parameter?
I know I can fix this by defining setup as |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Aleksey Levenstein (@levenleven) #16343 should have fixed this, but I don't think it shipped in the RC. Are you running 2.4.1 (the official release) or 2.4.0 (the RC). |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Nathan Shively-Sanders (@sandersn) Ok, thanks. Tried in playground, not sure which version is running there. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Oops, I think the playground may still be running 2.3. Daniel Rosenwasser (@DanielRosenwasser) did you update to 2.4 yet? Is it possible to add the version in small print when you do? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I would like to define a type for "non-thenables". I was assuming the following would work: However I get the "has no properties in common with" type error. After this change, how do I define a type for all values that do not have a |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
type NotThenable = { then?: never; [others: string]: any } | number | string | boolean | symbol; const x: NotThenable = 10; const x1: NotThenable = {}; const x2: NotThenable = { m: 10 }; const x3: NotThenable = { then: () => null }; |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Ryan Cavanaugh (@RyanCavanaugh) I was assuming |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I don't understand the question. What is |
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.
All Optional Object Interface Converts to any
There was an error while loading. Please reload this page.