-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Conversation
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).
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.)
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.
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; |
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.
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.
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 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?
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 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!
The basics
npm run format
andnpm run lint
The details
Resolves
Part of #6828.