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.Options
andBlocklyOptions
- the inject fn takes the former, but really should take the latter - A
BlockSvg
should have a workspace of typeWorkspaceSvg
BlockSvg.render
is missingWorkspaceSvg.newBlock
should return aBlockSvg
Events.Abstract
should ideally have a type property, rather than individual subclasses having itIcon
is 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.Msg
is declared as a module with a singleLOGIC_HUE
prop, 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.getVariable
returnsBlockly.VariableModel
but should beBlockly.VariableModel | null
according 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 FreeTop 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
Top GitHub Comments
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.register
fieldClass
param appears to be declared incorrectly…The blockly.d.ts declares
register
as:but
fieldClass
should be an object containing afromJson
function rather than just a function.