TypeScript definition problems
See original GitHub issueThe current blockly.d.ts TypeScript definition file does not accurately describe the data types in many places of the API, either through errors in the JSDoc types, insufficiently rich typing, or just incompatibilities between Closure and TS.
I’m currently upgrading our codebase to use Blockly July 2019 release, from its npm package rather than directly from the repo, and the supplied TypeScript definitions, rather than our very outdated and hacked definitions.
I’m opening this issue to start documenting the areas in which I’ve had to patch up or workaround issues in the supplied blockly.d.ts file…
- Mismatch between
Blockly.OptionsandBlocklyOptions- the inject fn takes the former, but really should take the latter - A
BlockSvgshould have a workspace of typeWorkspaceSvg BlockSvg.renderis missingWorkspaceSvg.newBlockshould return aBlockSvgEvents.Abstractshould ideally have a type property, rather than individual subclasses having itIconis missing some internal props and methods, which makes adding a custom Icon a pain
I’ve managed to fix above with the following…
import Blockly from 'blockly'
declare module 'blockly' {
interface BlockSvg {
workspace: Blockly.WorkspaceSvg
render(opt_bubble?: boolean): void
}
interface Options extends Blockly.BlocklyOptions {
}
interface WorkspaceSvg {
newBlock(prototypeName: string, opt_id?: string): Blockly.BlockSvg
}
interface Icon {
block_: Blockly.BlockSvg
iconGroup_?: SVGElement
drawIcon_(group: SVGElement): void
setVisible(visible: boolean): void
}
namespace Events {
interface Abstract {
type: string
}
}
}
Blockly.Msgis declared as a module with a singleLOGIC_HUEprop, preventing arbitrary overrides within TS code, really it should be declared as aRecord<string, string>to allow any message key to be overridden. The only work-around I’ve found for this is use of// @ts-ignore😦Blockly.VariableMap.prototype.getVariablereturnsBlockly.VariableModelbut should beBlockly.VariableModel | nullaccording to the docs
more to come…
Issue Analytics
- State:
- Created 4 years ago
- Comments:14 (8 by maintainers)
Top Results From Across the Web
Problems with TypeScript - Hacker News
TypeScript's major weakness is that it doesn't want to break away from Javascript. That strict dedication to being a superset means the type ......
Read more >Problems With TypeScript in 2020 - Execute Program
When used as a long-lived watcher process, TypeScript has broken this trend: it's buggy. The compiler tends to hit bugs when files are...
Read more >TypeScript: JavaScript With Syntax For Types.
TypeScript is a strongly typed programming language that builds on JavaScript, giving you better tooling at any scale. Try TypeScript Now. Online or...
Read more >TypeScript Done Wrong - OpenReplay Blog
So what's the problem then? As it turns out, the private keyword, which you'd use to define a private property in your class,...
Read more >7 really good reasons not to use TypeScript - everyday.codes
Any network calls, system libraries, platform-specific APIs and non-typed third-party libraries have no way of communicating with TypeScript. As ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Adding more to this. The different renderers we publish are currently not included in the blockly.d.ts
Hey gang, finally getting round to another Blockly update, from 3.20200123.1 to 3.20200625.2, so I thought I should keep this ticket updated.
Here are my type fixes for this release…
The most notable change being the
Blockly.fieldRegistry.registerfieldClassparam appears to be declared incorrectly…The blockly.d.ts declares
registeras:but
fieldClassshould be an object containing afromJsonfunction rather than just a function.