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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(blocks): Migrate blocks/lists.js to TypeScript #6902

Merged
merged 5 commits into from
Apr 18, 2023

Conversation

cpcallen
Copy link
Contributor

The basics

  • I branched from develop
  • My pull request is against develop
  • My code follows the style guide
  • I ran npm run format and npm run lint

The details

Resolves

Part of #6828.

Not running clang-format on this as for some reason it decides
half way through the file to indent everything after that by
an extra four spaces (and then has to re-wrap a bunch of lines
that are consequently too long).
blocks/lists.ts Outdated Show resolved Hide resolved
blocks/lists.ts Show resolved Hide resolved
blocks/lists.ts Show resolved Hide resolved
blocks/lists.ts Outdated Show resolved Hide resolved
blocks/lists.ts Show resolved Hide resolved
It turns out that the way I originally specified the types for
the mixins meant that they were all 'any', which is a bit
useless.  Change them so that tsc actually typechecks
properties (including method calls) on the mixed-in blocks,
and then fix the numerous additional type errors which
doing this revealed.

(By "fix", I mean apply "as" casts and "!"s as required to
suppress type errors from tsc.  Actually fixing the code in a
way that makes the blocks meaningfully more bulletproof is
left as an exercise to the reader - sorry, I mean: will be
dealt with in a future PR.)
Copy link
Collaborator

@BeksOmega BeksOmega left a comment

Choose a reason for hiding this comment

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

One comment, also question: did you want this to go into the upcoming release? If so, have you tested that the blocks actually function correctly?

/** Type of a 'lists_create_with' block. */
type CreateWithBlock = Block&ListCreateWithMixin;
interface ListCreateWithMixin extends ListCreateWithMixinType {
itemCount_: number;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is because this is added in the init function? Could we just define it in the mixin instead of defining it in the constructor?

Here & below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was wondering about that. I admit I am not 100% sure about the mechanics of block creation, so I thought it was safer to leave this as-is for now, but I'll add a note to #6920 to consider that.

Just to confirm: do you believe it is safe to init properties via (primitive-valued) properties on the mixin, instead of in the init method?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I do believe that that is safe. We actually do that in the procedure blocks (eg). All of the values get mixed into the block before the init method is called. So it's safe!

@cpcallen cpcallen marked this pull request as draft March 27, 2023 17:26
@cpcallen cpcallen marked this pull request as ready for review April 18, 2023 11:43
@cpcallen cpcallen merged commit 0177dff into google:develop Apr 18, 2023
@cpcallen cpcallen deleted the fix/6828/blocks/lists branch March 15, 2024 22:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants