types
1.0.0
Scratch不能为其库提供类型的定义,因此我们编写了自己的库。
此存储库仅包含香草(LLK)刮擦运行时和编辑器的类型。有关TurbowArp Runtimes中的其他类型,请参见 @Turbowarp/types-tw。
可以在以下位置找到一个更可读的打字稿定义的版本:https://turbowarp.github.io/types/
| 模块 | 地位 |
|---|---|
| scratch-vm | ✅ |
| 划痕渲染 | ✅ |
| Scratch-SVG渲染器 | ✅ |
| 划痕渲染范围 | ✅ |
| 从头开始 | ✅ |
| 刮擦存储 | ✅ |
| 刮擦者 | ✅ |
| 刮擦块 | ? |
| 刮擦gui redux | ✅ |
| 刮擦式redux | ✅ |
| 刮擦www redux |
首先,安装类型:
npm install @turbowarp/types
接下来,您必须使用tsconfig.json配置打字稿,以了解如何找到类型。
{
"compilerOptions" : {
// If you use require() or "module": "CommonJS", remove these lines.
// If you use "module": "ES6", synthetic default imports are required.
"module" : "ES6" ,
"allowSyntheticDefaultImports" : true ,
// Tell TypeScript where to find the types for Scratch libraries.
"paths" : {
"scratch-vm" : [ "./node_modules/@turbowarp/types/index.d.ts" ] ,
"scratch-render" : [ "./node_modules/@turbowarp/types/index.d.ts" ] ,
"scratch-svg-renderer" : [ "./node_modules/@turbowarp/types/index.d.ts" ] ,
"scratch-render-fonts" : [ "./node_modules/@turbowarp/types/index.d.ts" ] ,
"scratch-storage" : [ "./node_modules/@turbowarp/types/index.d.ts" ] ,
"scratch-audio" : [ "./node_modules/@turbowarp/types/index.d.ts" ] ,
"scratch-parser" : [ "./node_modules/@turbowarp/types/index.d.ts" ] ,
"scratch-blocks" : [ "./node_modules/@turbowarp/types/index.d.ts" ]
} ,
// Recommended strictness settings. Change as you please.
"strictNullChecks" : true ,
"noImplicitAny" : true ,
"noImplicitThis" : true
}
}然后在您的JavaScript或Typescript中:
import VM from 'scratch-vm' ;
const vm = new VM ( ) ;
vm . loadProject ( /* read a project somehow */ new ArrayBuffer ( 100 ) )
. then ( ( ) => {
vm . start ( ) ;
vm . greenFlag ( ) ;
} ) ;或者,如果您仍然使用require():
const VM = require ( 'scratch-vm' ) ;
const vm = new VM ( ) ;
vm . loadProject ( /* read a project somehow */ new ArrayBuffer ( 100 ) )
. then ( ( ) => {
vm . start ( ) ;
vm . greenFlag ( ) ;
} ) ; tests文件夹中有一些测试。这些文件永远不会实际运行,但是将检查代码。
类型定义和测试代码均在Apache 2.0许可下许可。
所记录的图书馆可能具有不同的许可。