Uh oh!
There was an error while loading. Please reload this page.
Change the default type parameter constraints and defaults to unknown from {} - #30637
Conversation
Wesley Wigham (weswigham)
commented
Mar 28, 2019
It is time - TypeScript Bot (@typescript-bot) test this & TypeScript Bot (@typescript-bot) run dt |
Heya Wesley Wigham (@weswigham), I've started to run the Definitely Typed test suite on this PR at 5224a6a. You can monitor the build here. It should now contribute to this PR's status checks. |
Heya Wesley Wigham (@weswigham), I've started to run the extended test suite on this PR at 5224a6a. You can monitor the build here. It should now contribute to this PR's status checks. |
unknown from {}unknown from {}Wesley Wigham (weswigham)
commented
Mar 28, 2019
At first glance, I really like most of the RWC breaks. (Once beyond all the {} -> unknown surface-level message changes.) Many of the new errors are things that point out that "hey, There's definitely a lot of baseline churn here, but this does seem to do good things. |
The DT changes are super simple to summarize:
And that seems to be it. I don't think this is actually as breaking as we thought it could be. |
Wesley Wigham (weswigham)
commented
Mar 29, 2019
TypeScript Bot (@typescript-bot) test this & TypeScript Bot (@typescript-bot) run dt - Between the changes to this PR and the small modifications I've made to DT, I expect this PR to be pretty clean now. We very well may be able to merge this on Monday and ship it out in a 3.5 nightly unflagged ❤️ |
Heya Wesley Wigham (@weswigham), I've started to run the Definitely Typed test suite on this PR at 66049c3. You can monitor the build here. It should now contribute to this PR's status checks. |
Heya Wesley Wigham (@weswigham), I've started to run the extended test suite on this PR at 66049c3. You can monitor the build here. It should now contribute to this PR's status checks. |
Wesley Wigham (weswigham)
commented
Mar 29, 2019
RWC test results now consist of:
which is exactly the kind of thing we wanted to catch here - that !!!errorTS2339: Property'toString'doesnotexistontype'never'.which was issued in the !!!errorTS2339: Property'hasOwnProperty'doesnotexistontype'T'.as an unconstrained type parameter cannot be treated as an object (as mentioned in the design meeting notes). Catching this was also one of our motivating examples. ❤️ !!!errorTS2339: Property'finish'doesnotexistontype'{}'.become !!!errorTS2571: Objectisoftype'unknown'.
...and that's it. All in all, all positive or neutral changes. Nice~ Now to wait for the DT results. |
Wesley Wigham (weswigham)
commented
Mar 30, 2019
I'll need to run DT again; I missed updating an old version of In any case, I have super high confidence in this change now. I'm going to take this out of draft state. ❤️ |
Wesley Wigham (weswigham)
commented
Mar 30, 2019
TypeScript Bot (@typescript-bot) run dt should now just have two react-dnd failures (from them using the same bad circular constraint as |
Heya Wesley Wigham (@weswigham), I've started to run the Definitely Typed test suite on this PR at 66049c3. You can monitor the build here. It should now contribute to this PR's status checks. |
Wesley Wigham (weswigham)
commented
Apr 3, 2019
Ping Anders Hejlsberg (@ahejlsberg) for review so we can merge this ❤️ |
Anders Hejlsberg (ahejlsberg)
left a comment
There was a problem hiding this comment.
Just one minor suggested fix, otherwise looks good.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Javier Gonzalez (xaviergonz)
commented
Apr 30, 2019
Ahh, I just wish there was some way to declare an actual empty object |
Anders Hejlsberg (ahejlsberg)
commented
May 1, 2019
Any reason |
Anders Hejlsberg (@ahejlsberg) |
object doesn't model an empty object as well AFAIK consta1: object={}// (no-error) goodconstb1: object={y: 5}// (no-error) weird, nobody says y should be thereconstc1: object=[5]// (no-error) weird, I guess an array is an "object", but still...constd1: object=5// (error) good, not an objectThe issue I have really is that I use something like this to turn props that can take an undefined value into optional props: typeIsOptionalValue<C>=undefinedextendsC ? true: nevertypeDefinablePropsNames<T>={[KinkeyofT]: IsOptionalValue<T[K]>extendsnever ? K : never}[keyofT]typeMakeUndefinedPropsOptional<PC>={[PinDefinablePropsNames<PC>]: PC[P]}&Partial<PC>But it seems to break when the first object generated by MakeUndefinedPropsOptional ends up being an empty object because all properties can be turned into optionals consta: MakeUndefinedPropsOptional<{}>=[]// is ok :-(constb: MakeUndefinedPropsOptional<{a: number|undefined}>=[]// is ok :-(constc: MakeUndefinedPropsOptional<{a: number}>=[]// it is not ok :Dconstd: MakeUndefinedPropsOptional<{a: number}>={a: 5}// it is ok :DMaybe another option to fix it would be if one could modify the "?" modifier based on some extends clause, like: typeMakeUndefinedPropsOptional<PC>={[PinkeyofPC](undefinedextendsPC[P] ? +? : -?): PC[P]}but that's not there |
Bruce Pascoe (fatcerberus)
commented
May 10, 2019
Overall 👍 on this change, but I am concerned about one thing: the |
We've oft talked about wanting to try this to see how "bad" the breaks this could cause may be. Well, here's me, seeing how bad the breaks are.
Incidentally, this exposes #30634, since swapping the type parameter constraint from
{}tounknownmakes unconstrained type parameters no longer assignable to every partial type. (Type parameters which explicitly extend{}still will be, though.) This means I already know this PR breaksreact-redux.Looking over the test baseline changes, most are procedural (just swapping from
{}tounknown) and a few of the error changes from what I can understand simply fall out from inferring from anunknownconstraint instead of a{}(and, IMO, for the most part act in a more expected way).Take for example the
tsxerror deletion and change - they both stem from those tests not defining someJSXnamespace elements. I now default those tounknowninstead ofemptyObjectType, which means attempts to pass properties to them no longer result in excess property errors. I think this is better (not that I think anyone should be using JSX without a well-defined JSX namespace), so I've kept it (however if there's disagreement here, this part is easy to undo separately from the type parameter default change).