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許可下許可。
所記錄的圖書館可能具有不同的許可。