Scratch tidak memberikan definisi jenis untuk perpustakaan mereka, jadi kami menulis sendiri.
Repositori ini hanya berisi jenis untuk runtime dan editor goresan vanilla (LLK). Untuk jenis tambahan di runtime Turbowarp, lihat @Turbowarp/Type-TW.
Versi definisi TypeScript yang mungkin lebih dapat dibaca manusia dapat ditemukan di: https://turbowarp.github.io/types/
| Modul | Status |
|---|---|
| goresan-vm | ✅ |
| Render goresan | ✅ |
| Gores-SVG-Renderer | ✅ |
| Gores-render-font | ✅ |
| Audio awal | ✅ |
| penyimpanan goresan | ✅ |
| Gores-parser | ✅ |
| blok gores | ? |
| Redux Scratch-Gui | ✅ |
| Redux gores-cat | ✅ |
| gores-www redux |
Pertama, instal jenisnya:
npm install @turbowarp/types
Selanjutnya, Anda harus menggunakan tsconfig.json untuk mengkonfigurasi naskah untuk mengetahui cara menemukan jenisnya.
{
"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
}
}Kemudian di javascript atau naskah Anda:
import VM from 'scratch-vm' ;
const vm = new VM ( ) ;
vm . loadProject ( /* read a project somehow */ new ArrayBuffer ( 100 ) )
. then ( ( ) => {
vm . start ( ) ;
vm . greenFlag ( ) ;
} ) ;Atau jika Anda masih menggunakan membutuhkan ():
const VM = require ( 'scratch-vm' ) ;
const vm = new VM ( ) ;
vm . loadProject ( /* read a project somehow */ new ArrayBuffer ( 100 ) )
. then ( ( ) => {
vm . start ( ) ;
vm . greenFlag ( ) ;
} ) ; Ada beberapa tes di folder tests . File -file ini tidak pernah benar -benar dijalankan, tetapi kode akan diperiksa jenisnya.
Jenis definisi dan kode pengujian dilisensikan di bawah lisensi Apache 2.0.
Perpustakaan yang sedang didokumentasikan mungkin berada di bawah lisensi yang berbeda.