AEM Sling to Typescript Converter
A CLI tool which scans a projects for Apache Sling models and generates equivalent Typescript definitions.
This is a useful tool for any AEM + React Typescript projects, promoting type-safety between the BE and FE.
Installation
Install package as dev depedency
npm install --save-dev aem-sling-2-ts
package.json
Add script to {
"scripts": {
"generate:sling-ts": "aem-sling-2-ts ../core ./src/types/sling-interfaces.d.ts"
}
}
Usage
The generate the Typescript definition file containing the sling model interfaces, run:
npm run generate:sling-ts
Importing Definitions
After generating the .d.ts
definition file, the interfaces can be referenced globally:
const MyComponent = (props: Sling.ExampleModelProps) => (
<div>{props.example}</div>
)
Future scope
Make code namespace aware!- Scaffold react components from Sling models
- Improved type mappings