Scratch не предоставляет определения типа для их библиотек, поэтому мы написали свои собственные.
Этот репозиторий содержит только типы для выполнения ванили (LLK) и редактора. Для дополнительных типов в Turbowarp-времени см. @Turbowarp/Types-TW.
Возможно, более читаемой на человеке версию определений типографии можно найти по адресу: https://turbowarp.github.io/types/
| Модуль | Статус |
|---|---|
| Scratch-Vm | ✅ |
| царапина | ✅ |
| Scratch-SVG-Renderer | ✅ |
| царапин-рендерины | ✅ |
| Скретч-Аудио | ✅ |
| царапина | ✅ |
| царапина | ✅ |
| царапины | ? |
| Скрыб-гуй 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 ( ) ;
} ) ;Или если вы все еще используете 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.
Задокументированные библиотеки могут находиться под разными лицензиями.