Skip to content
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

RFC: New name for strictOptionalProperties #44604

Closed
RyanCavanaugh opened this issue Jun 15, 2021 · 21 comments
Closed

RFC: New name for strictOptionalProperties #44604

RyanCavanaugh opened this issue Jun 15, 2021 · 21 comments
Labels
Discussion Issues which may not have code impact

Comments

@RyanCavanaugh
Copy link
Member

RyanCavanaugh commented Jun 15, 2021

Per discussion at #44421 and #44524, we're moving the flag currently named strictOptionalProperties out of the strict family and into the off-by-default category inhabited by other options like noImplicitReturns, noUncheckedIndexedAccess, and allowUmdGlobalAccess

As such, we need a new name for this. As a refresher, the flag makes it so that a property that is optional, e.g. { x?: string }, cannot be initialized with the actual value undefined, e.g. someObj.x = undefined. If this flag is not set, then today's behavior of allowing undefined values to be assigned into optional properties remains. There is no effect on parameters.

Please only post name suggestions (one per comment) and votes; actual discussion on the flag should remain at #44421. Happy coding!

@RyanCavanaugh RyanCavanaugh added the Discussion Issues which may not have code impact label Jun 15, 2021
@fatcerberus
Copy link

There is no effect on

I don’t think you finished this sentence… 😉

@RyanCavanaugh
Copy link
Member Author

RyanCavanaugh commented Jun 15, 2021

Thanks, fixed 😅

@fatcerberus
Copy link

strictOptionalProperties is such a perfect name, I can’t think of anything better. noExplicitUndefinedForOptionalProperties maybe, but that’s really verbose and also maybe misleading since you can still declare properties as being in a union with undefined

@aleph-naught2tog
Copy link

noExplicitUndefinedValuesForOptionalProperties

@fatcerberus
Copy link

Yeah, that has the same problem I mentioned in that you could still declare the property as e.g. foo?: string | undefined

@RyanCavanaugh
Copy link
Member Author

RyanCavanaugh commented Jun 15, 2021

noImplicitPropertyUndefined

@johnnyreilly
Copy link

noUndefinedOptionalProperties

@Faithfinder
Copy link

noImplicitUndefinedInOptionals

@kungfusheep
Copy link

noExplicitUndefinedOptionals

@aleph-naught2tog
Copy link

aleph-naught2tog commented Jun 15, 2021

noOptionalsInitializedWithUndefined

@aleph-naught2tog
Copy link

noInitializingOptionalPropertiesWithUndefined

@fatcerberus
Copy link

For the people who thumbs-downed my comment: That wasn't an opinion, I was simply pointing out that even with SOP turned on, this is still allowed:

interface Foo {
    foo?: string | undefined;
}

let x: Foo = { foo: undefined };

...which is why I can't come up with a good name for the flag other than the one it already has, and why I don't like the noExplicitUndefined variants.

@DanielRosenwasser
Copy link
Member

noExplicitUndefinedInOptionals

@LukeNotable
Copy link

I'm not following the noExplict proposals: the option is whether to add an implicit | undefined when declaring { foo?: Bar } and thus getting { foo?: Bar | undefined }.

noImplicitOptionalPropertyUndefined

@bodograumann
Copy link

distinguishMissingFromUndefined

Cf. #13195

@fatcerberus
Copy link

Alternatively: stricterOptionalProperties. It’s “too strict” for strict (therefore stricter) but still tightens up the type system.

@tjjfvi
Copy link
Contributor

tjjfvi commented Jun 16, 2021

pedanticOptionalProperties

@fatcerberus
Copy link

@MartinJohns I'm not sure why you're confused about my comment?

@softwareCobbler
Copy link
Contributor

softwareCobbler commented Jun 16, 2021

noImplicitUndefinedInOptionalProperties

@fson
Copy link

fson commented Jun 17, 2021

distinctUndefinedAndOptionalProperties

@RyanCavanaugh
Copy link
Member Author

RyanCavanaugh commented Jun 17, 2021

Thanks for the ideas, everyone - this really got us thinking. Not sure if Daniel is posting notes so here's my recollection from memory.

  • We didn't like the noExplicit variants because it implies that it's a switch to ban x?: T | undefined, when really it's the opposite
  • The noImplicit variants were OK; noImplicitUndefinedInOptionalProperties is by far the clearest name but is longer than our next-longest commonly-used flag noUncheckedIndexedAccess by quite a few characters
  • Names that implied stronger guarantees were rejected because optional properties are still unsound through 2-hop assignments
  • (much noodling is had, along with sadness that we can't really put this in strict)
  • exactOptionalPropertyTypes was floated and was met with universal lack of dread, which made it a strong contender
    • Implies a possible future exact family, though we're by no means roadmapping that
    • Does what it says on the tin: The type of an optional property is exactly what you wrote, not that type plus undefined

PR up at #44626

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Discussion Issues which may not have code impact
Projects
None yet
Development

No branches or pull requests