Skip to content

Conversation

@quisido
Copy link
Contributor

@quisido quisido commented Sep 5, 2021

Before submitting a pull request, please take a look at our
Contributing guidelines and verify:

  • If you've added code that should be tested, please add tests.
  • Ensure your code lints and the test suite passes (yarn lint) & (yarn test).

I cannot lint in this instance, because I am PR'ing from the GitHub web UI. 🙃
Hopefully the PRs have GitHub workflows that will lint on my behalf.


TypeScript 4.4 added a new compiler option, exactOptionalPropertyTypes, which distinguishes between {} and { key: undefined }. With this flag, f(key?: string) may either be f() or f('str'), but may not be f(undefined). In most cases, f(undefined) should be acceptable, including in Sentry.

Example:

function myInit({ allowUrls }) {
  init({ allowUrls });
}

myInit({}); // should be valid,

In the above example, TypeScript 4.4 throws an error with the flag because allowUrls must either be an array or not set at all. It does not allow this code such that it is set to undefined.

For future consumer-facing code, please replace [key]?: T with [key]?: T | undefined. 🙃


Sorry in advance that each file is a separate PR. This also, however, allows blast radius to be reduced, and is particularly relevant for any properties where undefined should not be supported.

@kamilogorek
Copy link
Contributor

Closed in favor of #3960

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants