Using Typescript
-
I am building a Gutenberg block which I have previously had working and am now refactoring to use Typescript. I am getting an error where it tries to import the block.json file and as a result the block does not get registered in the editor.
Here is my tsconfig.js file:
{ "compilerOptions": { "outDir": "./build/", "noImplicitAny": true, "module": "commonjs", "target": "es5", "jsx": "react", "allowJs": true, "moduleResolution": "node", "allowSyntheticDefaultImports": true, "esModuleInterop": true, "resolveJsonModule": true }, "include": [ "src/*" ] }Here is the block.json:
{ "apiVersion": 2, "name": "bootstrap-components/accordion", "version": "0.1.0", "title": "Accordion Block", "category": "widgets", "icon": "smiley", "description": "Example block written with ESNext standard and JSX support – build step required.", "supports": { "html": false }, "textdomain": "bootstrap-components", "editorScript": "file:../../../build/index.js", "editorStyle": "file:../../../build/index.css", "style": "file:../../../build/style-index.css" }which is imported into index.tsx using import metadata from ‘./block.json’;.
The error I get is:
Argument of type '{ apiVersion: number; name: string; version: string; title: string; category: string; icon: string; description: string; supports: { html: boolean; }; textdomain: string; editorScript: string; editorStyle: string; style: string; }' is not assignable to parameter of type 'string'.ts(2345)Any help much appreciated.
The topic ‘Using Typescript’ is closed to new replies.