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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1076: nominal subtyping for ids #1077

Merged
merged 3 commits into from Aug 15, 2021
Merged

Conversation

twschiller
Copy link
Contributor

@twschiller twschiller commented Aug 15, 2021

Closes #1076
Closes #1073

  • Introduces nominal subtyping for UUID vs. RegistryIds
  • Fixes brick generation: Brick headers not being generated聽#1073 (馃う TypeScript not blocking Object.values on Maps)
  • Remove header generation code for extensionPoints, as we don't have any hard-coded extension points anymore
  • Fail build if no headers are generated

Copy link
Collaborator

@fregante fregante left a 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) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change?

Copy link
Contributor Author

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)

Comment on lines +37 to +40
export type UUID = string & {
// Nominal subtyping
_uuidBrand: never;
};
Copy link
Collaborator

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: 馃槄

https://github.com/sindresorhus/refined-github/blob/ac8de6bd0ef0a6016732a69556e4eb9c014cfd38/source/globals.d.ts#L5

Copy link
Contributor Author

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

@twschiller twschiller merged commit 77fe2a8 into main Aug 15, 2021
@twschiller twschiller deleted the feature/1076-id-nominal-subtyping branch August 15, 2021 17:02
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.

Nominal typing for ids Brick headers not being generated
2 participants