-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
♻️ Enable TS type-checking on #core/assert #37171
Conversation
Hey @jridgewell! These files were changed:
|
@@ -79,19 +77,18 @@ export function devAssert( | |||
* For more details see `assert`. | |||
* | |||
* @param {*} shouldBeElement | |||
* @param {!Array<*>|string=} opt_message The assertion message | |||
* @return {!Element} The value of shouldBeTrueish. | |||
* @param {Array<*>|string=} opt_message The assertion message |
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.
Didn't we discuss preferring T[] vs. Array
* @param {Array<*>|string=} opt_message The assertion message | |
* @param {any[]|string=} opt_message The assertion message |
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.
- I'm not positive if
any
works in JSDoc comments 2) Yes, I agree, but also I haven't been updating it everywhere. Would prefer to set up TSLint and let it do it for us
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.
- any does work
- makes sense, especially if its auto-fixable.
@@ -8,6 +8,8 @@ | |||
"strictNullChecks": true, | |||
"lib": ["dom", "esnext", "es6"], | |||
"paths": { | |||
"#core/assert": ["./assert"], |
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.
nit: does this work:
'#core': ['.']
'#core/*': ['./*']
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.
It will once context
is allowed (yes we could exclude context
directly instead). That's where we'll be very soon.
59d4f6c
to
c325cae
Compare
TS supports type narrowing via type assertions, but does so in a way that is mutually exclusive with type-checking a returned value. See microsoft/TypeScript#34636 and microsoft/TypeScript#40562
Workaround: Type-checking for now will support assertion format, but code itself will still return the asserted values as normal (by casting to
void
). This means that as code is migrated to pass type-checking, it'll have to update how it calls these assertion functions, but any existing code relying on the return pattern will continue to function as normal.Explanation of why this is annoying/doesn't fit both use-cases: