-
Notifications
You must be signed in to change notification settings - Fork 206
Fix type issue with the latest frontend-shared version #3738
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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #3738 +/- ##
=======================================
Coverage 98.95% 98.95%
=======================================
Files 211 211
Lines 7671 7671
Branches 1731 1731
=======================================
Hits 7591 7591
Misses 80 80 Continue to review full report at Codecov.
|
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 suggest moving the cast to a different place, both to reduce the amount of annotations needed in future and to get more helpful error messages.
dev-server/ui-playground/index.js
Outdated
@@ -3,11 +3,15 @@ import ButtonPatterns from './components/ButtonPatterns'; | |||
|
|||
import sidebarIcons from '../../src/sidebar/icons'; | |||
|
|||
/** @type {import('@hypothesis/frontend-shared/lib/pattern-library').PlaygroundRoute['group']} */ |
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'll be easier to add the cast to the extraRoute
definition:
/** @type {import('@hypothesis/frontend-shared/lib/pattern-library').PlaygroundRoute[]} */
const extraRoutes = [
{
route: '/buttons',
title: 'Buttons',
component: ButtonPatterns,
group: 'components',
},
];
This way you only have to specify a type once if there are multiple fields like group
. You'll also get an earlier error if the extraRoutes
object does not have the intended structure.
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.
Much better, thanks.
An alternative approach that will be available with typescript 4.5 is:
group: /** @type {const} */ ('components')
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.
Ah, that's useful to know. I think I'd still prefer to type extraRoutes
in this particular case in order to communicate intent to readers.
In the latest version of the frontent-shared package, `extraRoute` has a mandatory property `group` that must be either `"home" | "foundations" | "patterns" | "components"`; There are three ways to fix this: * make the `group` property optional in the frontend-shared package (I don't know if that's a good idea). * cast the `string` type to the one of the allowed types: ` group: /** @type {'components'} */ ('components'),` * cast the `extraRoute` (this PR).
9008aa8
to
2e5a0bd
Compare
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 think this change is fine and innocuous for the moment.
I think it would likely be more ergonomic for authors in the future if the package weren't so persnickity about groups and their type. Perhaps a sensible default fallback for extraRoutes
that lack a group
? I'll track this (in frontend-shared
).
This linting grumpiness is just popping up now in the newest version of the package, which suggests that this is a side effect of the updated type-declaration generation? That is, typing for this hasn't been touched directly in some time. Any insight you might have on that would be helpful!
@lyzadanger, you are right this is caused by changes in Previously, only JS files that were 'linked' to In version 3.8.1, type definitions are generated for all JS files: |
In the latest version of the frontent-shared package,
extraRoute
has amandatory property
group
that must be either"home" | "foundations" | "patterns" | "components"
;There are three ways to fix this:
make the
group
property optional in the frontend-shared package (Idon't know if that's a good idea).
cast the
string
type to one of the allowed types:group: /** @type {'components'} */ ('components'),
convert the
string
type to const without casting (this PR).