Skip to content

Blockly Locale Typescript Issues with Latest Release #5818

@reece-berens

Description

@reece-berens

Describe the bug
A couple typescript errors appear in my project when attempting to set the locale of Blockly.

When attempting to import the correct language module, the following error appears:

Could not find a declaration file for module 'blockly/msg/en'. '<myfilepath>/node_modules/blockly/msg/en.js' implicitly has an 'any' type.
If the 'blockly' package actually exposes this module, try adding a new declaration (.d.ts) file containing `declare module 'blockly/msg/en';`

When attempting to use the Blockly.setLocale() function, the following error appears:
Property 'setLocale' does not exist on type 'typeof import("blockly")'

This code was working fine with version 6.20210701.0, but appeared when I upgraded to version 7.20211209.0 from NPM. I didn't see anything in the release notes related to this issue, so I'm assuming this is not intended.

To Reproduce
Below is the code I am using. It has not changed between the two versions.

import React from 'react';
import './App.css';
import BlocklyComponent from "./blocklyComponent";
import Blockly from "blockly";
import CustomBlocklyBlocks from "./customBlockly/blockDef";
import enLocale from "blockly/msg/en"; //error on this line

function App() {
    Blockly.setLocale(enLocale); //error on this line
    Blockly.defineBlocksWithJsonArray(CustomBlocklyBlocks);
    return (
        <div>
            <p>Test paragraph</p>
            <BlocklyComponent />
        </div>
    );
}

export default App;

Expected behavior
The user should not receive any typescript errors when attempting to set the locale for their specific Blockly instance.

Additional context
I am using typescript version 4.5.2 and React version 17.0.2. I am using Visual Studio Code (version 1.63.0) as my IDE.
This isn't super important for me as I just need the English messages, but I thought I'd open this issue just in case this is an issue for anyone who does need to change languages.
Feel free to let me know if you need any other information.
Thank you!

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions