-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Design Meeting Notes, 1/18/2023 #52296
Comments
Isn’t the “any-like” function type |
IIRC - yes. But the fact that it's not |
While some of those are contrived and uncommon - this isn't quite that (in my opinion): function stringify(a?: object): string {
return JSON.stringify(a)
}
stringify(undefined) // undefined, oops I had a production issue recently cause I accidentally passed an optional param/property to a stringifying function and somewhere down the road I expected to have a guaranteed |
Also IIRC |
@Andarist I tried to capture it in the notes, but the new overload doesn't model that type correctly anyway - |
Also - TIL that |
The thing that got us super derailed on the JSON.stringify thing was that people have the entirely reasonable assumption that if they pass something that isn't Thus while you could write a conditional type to distribute over the possible inputs and say that it only possibly returns So we're basically stuck with two options:
Regardless, if you do want the alternate behavior, it's very easy to add an interface merge to your project and get the "always might be undefined" behavior. No commandline flags / custom lib / etc needed. Just hope that you don't overly habituate on writing |
Right, I see the reasoning and I agree that adding I understand though that this is a very hard/impossible choice to make here and there is no way to satisfy everybody.
Well, at least that surfaces the possibility to the writer and reader, it educates them about this problem. So this is a good thing - even if people start adding |
To a point. The design goals do include the caveat “strike a balance between correctness and productivity” for a reason. JS has no undefined behavior and soundness is explicitly not an end goal so it’s always a subjective judgment call what should be a compile-time error vs. not. |
@fatcerberus This code doesn’t cause any errors: declare const f: (...args: never) => unknown
f() |
That looks like a bug. |
Found the issue for that bug: #48840 |
newLine
andforceConsistentFileNames
Defaults#51909
newLine
tolf
?forceConsistentFileNames
totrue
?--newLine lf
by default.--forceConsistentFileNames true
by default.catch
Clause Variables#52240
useUnknownInCatchVariables
betweentrue
andfalse
.true
, the annotations are ignored, and destructured declarations are permitted andunknown
.useUnknownInCatchVariables
.Comparison Operators
#52036
#52048
Number < number
now disallowedstring | number < number
now disallowedunknown < number
now disallowednumber
(e.g.Date
)?valueOf
?[Symbol.toPrimitive]
?JSON.stringify
#51897
#52250
stringify
can returnundefined
.Function
can have atoJSON
method.never
works.(() => string) | string
today.stringify
because of these contrived-but-uncommon cases feels unreasonable.JSON
with something that returnsundefined
.Picking Between Types from Type Predicates and Original Types
#50916
instanceof
too.unknown
andany
are mutual subtypes.any
a strict supertype ofunknown
.When the type IDs are not compared directly.
So for e.g.
Array<any>
vs.Array<unknown>
- butArray
is not special.Now you always end up with
Box<any>[]
.{}
and any non-empty object type.The type of an assignment expression is always the right side:
Hmm...
{}
object type has "inverted" subtype behavior.b = {}
, we have to propagate out some information, or further narrow based on the left side(?)(...args: any[]) => any
should be a super-type of all functions?(...args: never[]) => unknown
?The text was updated successfully, but these errors were encountered: