fix: manually add typings for generator classes #7824
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The basics
The details
Resolves
Fixes missing generator types.
Proposed Changes
Exports type for the
JavascriptGenerator
class and other similar classes in the other generator languages.Reason for Changes
Blockly exports both a
JavascriptGenerator
class, and ajavascriptGenerator
instance of that class. In most cases, folks use the instance. However, in some scenarios, a developer needs to access the class itself, whether to subclass or to use as a type in TypeScript. The class is exported and thus available in JavaScript, but it was not present in the.d.ts
files and therefore invisible to TypeScript tooling.The
.d.ts
files are currently manually maintained in Blockly v10. This is because for a while, generator classes were in JavaScript and no types were available. After converting them to TypeScript, more precise types are available, but it would be disruptive to TS developers to introduce them when previously the instance was typed asany
, so we maintained the manual typing. In Blockly v11, we'll switch to generated type definitions that will include full information for both the class and instance of the class.This PR only adds accurate typing for the class itself, not the instance. Because the class was not previously in TypeScript definitions at all, this isn't disruptive in the same way as it would be for the instance. If you wish to preview accurate typings for the instance as well as the class, please try the Blockly v11 beta by installing
blockly@beta
from npm.Test Coverage
Added a TypeScript test file.
Documentation
None, other than release notes.
Additional Information
We'll plan to put this in a patch release for Blockly v10.
Note, if you arrive here due to a merge conflict between develop and the rc/v11 branch, you probably just want to accept the changes from rc/v11. This PR is a partial (non-breaking) implementation of the changes in #7727 and #7750