odoo / owl

OWL: A web framework for structured, dynamic and maintainable applications
https://odoo.github.io/owl/
Other
1.11k stars 334 forks source link

Proposition: type-safe XML #1562

Open Arcasias opened 7 months ago

Arcasias commented 7 months ago

Proposition

Use type markers to ensure type safety in components' XML templates (e.g. <expression>:<type>="value"). This would only be applied in dev or test mode and would throw an error if the evaluated expression does not return the intended type.

Example

class Root extends Component {
    static props = {};
    static template = xml`
        <div t-att-class:string="className">
            Value <t t-esc:number="state.value" />
            <button t-on-click:function="onClick">Increment</button>
        </div>
    `;

    className = "my-class";

    setup() {
        this.state = reactive({ value: 0 });
    }

    onClick() {
        this.state.value++;
    }
}