Scratch ไม่ได้ให้คำจำกัดความประเภทสำหรับห้องสมุดของพวกเขาดังนั้นเราจึงเขียนของเราเอง
พื้นที่เก็บข้อมูลนี้มีเฉพาะประเภทสำหรับรันไทม์ของ Vanilla (LLK) รันไทม์และโปรแกรมแก้ไข สำหรับประเภทเพิ่มเติมใน turbowarp runtimes ให้ดู @turbowarp/types-tw
อาจพบคำจำกัดความของ TypeScript เวอร์ชันที่มนุษย์อ่านได้มากขึ้นได้ที่: https://turbowarp.github.io/types/
| โมดูล | สถานะ |
|---|---|
| Scratch-VM | |
| รอยขีดข่วน | |
| Scratch-SVG-renderer | |
| การสร้างรอยขีดข่วน | |
| รอยขีดข่วน | |
| การจัดเก็บรอยขีดข่วน | |
| รอยขีดข่วน | |
| รอยขีดข่วน | - |
| Scratch-gui redux | |
| Redux รอยขีดข่วน | |
| Scratch-www redux |
ก่อนอื่นติดตั้งประเภท:
npm install @turbowarp/types
ถัดไปคุณต้องใช้ tsconfig.json เพื่อกำหนดค่า TypeScript เพื่อทราบวิธีการค้นหาประเภท
{
"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 ( ) ;
} ) ;หรือถ้าคุณยังใช้ต้องการ ():
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
ห้องสมุดที่ได้รับการบันทึกอาจอยู่ภายใต้ใบอนุญาตที่แตกต่างกัน