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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
#1076: nominal subtyping for ids #1077
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
馃憤
@@ -44,7 +44,7 @@ const WAIT_LOADED_INTERVAL_MS = 25; | |||
async function installScriptOnce(): Promise<void> { | |||
// https://stackoverflow.com/questions/9515704/insert-code-into-the-page-context-using-a-content-script/9517879#9517879 | |||
// https://stackoverflow.com/questions/9602022/chrome-extension-retrieving-global-variable-from-webpage | |||
if (!_scriptPromise) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Linter was complaining about using "!" on a promise (which makes sense, as it's error-prone, since in most cases the intention would probably be using "!" on the result of the promise)
export type UUID = string & { | ||
// Nominal subtyping | ||
_uuidBrand: never; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Too bad TypeScript doesn't support this natively yet:
I think I achieved something similar with a plain string type before: 馃槄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In a past life I worked on https://checkerframework.org/, which allowed you apply additional type qualifiers to types in Java. Double that TypeScript will be getting support for it anytime soon, but you could do a lot of cool things with custom types
Definitely essential to have string union types in TypeScript, and they do have some wacky helpers e.g., for capitalizing string: https://www.typescriptlang.org/docs/handbook/utility-types.html#intrinsic-string-manipulation-types
Closes #1076
Closes #1073