-
Notifications
You must be signed in to change notification settings - Fork 178
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
TypeScript: Convert text-sets
package
#12274
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
Plugin builds for 366b793 are ready 🛎️!
|
Size Change: +29 B (0%) Total Size: 2.72 MB ℹ️ View Unchanged
|
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.
LGTM
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.
Overall looks great, just a few nits, mostly on overtyping where the type would be inferred by the compiler anyway.
@@ -89,5 +92,5 @@ export default async function loadTextSets() { | |||
}) | |||
); | |||
|
|||
return Object.fromEntries(results); | |||
return Object.fromEntries(results) as TextSets; |
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.
as
is a rather crude tool that should only be applied if no better tool exists, as it will actually ignore and suppress some potential errors. However, moving it to a typed variable or just setting the return type won't do the trick, because fromEntries
doesn't play nice (typed as returning any
).
This required updating the type system a bit as:
export enum TextSetType {
Cover = 'cover',
Step = 'step',
SectionHeader = 'section_header',
Editorial = 'editorial',
Contact = 'contact',
Table = 'table',
List = 'list',
Quote = 'quote',
}
export type TextSets = Partial<Record<TextSetType, TextSet[]>>;
And then loadTextSets
becomes:
export default async function loadTextSets(): Promise<TextSets> {
const results: [TextSetType, TextSet[]][] = await Promise.all(
Object.values(TextSetType).map(async (name) => [
name,
await loadTextSet(name),
])
);
return Object.fromEntries(results);
}
The Partial<>
is a bit annoying but I don't see a clean way around it? I feel this is cleaner, but it's probably just a nit really.
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.
If I am honest, I don't find your code easier to read or understand. I have pushed up my own version of the code, that is a little easier to follow. See ed4be89
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.
@barklund Can you take a look ?
Context
Summary
Relevant Technical Choices
To-do
User-facing changes
Testing Instructions
This PR can be tested by following these steps:
Reviews
Does this PR have a security-related impact?
Does this PR change what data or activity we track or use?
Does this PR have a legal-related impact?
Checklist
Type: XYZ
label to the PRFixes #12175