Replies: 5 comments 1 reply
-
|
I go back and forth on |
Beta Was this translation helpful? Give feedback.
-
|
I've been using But regardless of my personal opinion, I agree it should be required to ensure downstream compatibility. |
Beta Was this translation helpful? Give feedback.
-
|
@dfreeman and I were discussing this this morning and he pointed out that it's actually a bit weirder than "just require it" allows for: in fact, what is "safe" for a consumer depends on what the library has chosen, because of the way Consider the following two examples, with function exampleIn(arg: { foo?: string }) {
if ('foo' in arg) {
arg.foo.length;
}
}declare function exampleOut(): { foo?: string });In the The exact inverse is true for the (Notably, the check is an important one: the type system is catching real runtime issues!) The only way that this can be safe is not by requiring Footnotes
|
Beta Was this translation helpful? Give feedback.
-
|
Huh, good point. What about: require function exampleIn(arg: { foo?: string | undefined }) {
if ('foo' in arg) {
arg.foo.length;
}
} |
Beta Was this translation helpful? Give feedback.
-
|
Long-delayed follow-up: this has been integrated since either beta.3 or the (just-published) beta.4. 👍🏼 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Just as requiring
noUncheckedIndexedAccessis useful to ensure compatibility with downstream code, it may make sense to also requireexactOptionalPropertyTypes.Beta Was this translation helpful? Give feedback.
All reactions