Skip to content

Instantly share code, notes, and snippets.

@vjau
Created September 16, 2023 13:01
Show Gist options
  • Save vjau/f136c9ff37591cc853faf5a43025db7a to your computer and use it in GitHub Desktop.
Save vjau/f136c9ff37591cc853faf5a43025db7a to your computer and use it in GitHub Desktop.
Utility Typescript Type to know when exactOptionalPropertyTypes is set
type _Intersect = {a?:number} & {a:number|undefined};
//state of exactOptionalPropertyTypes
type IsExactOptional = _Intersect["a"] extends Exclude<_Intersect["a"], undefined> ? true : false;
@vjau
Copy link
Author

vjau commented Mar 16, 2025

Doesnt work past Typescript 4.6, but is easily replaced by

type IsExactOptional = {foo: undefined} extends {foo?:number} : false : true;

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