Type declarations for odoo
With odoo-typescript
you can use your favorite bundler to build your odoo modules.
Advantages of odoo-typescript
:
- Just use
npm install
to add dependencies - Out-of-the-box auto-completion for all odoo modules
Disadvantages:
- Extra build step
Aside from the type declarations odoo-typescript
also includes some methods:
Import an existing module
import * as ots from 'odoo-typescript/v18.0'
const owl = ots.require('@odoo/owl')
Define a module
import * as ots from 'odoo-typescript/v18.0'
import type { ORM } from 'odoo-typescript/v18.0/dist/addons/web/core/orm_service'
ots.define({
name: "@my_module/foo",
deps: {
hooks: "@web/core/utils/hooks",
owl: "@odoo/owl",
},
factory({hooks, owl}) {
const orm: ORM = hooks.useService("orm_service")
class MyComponent extends owl.Component {
// custom owl component
}
return {
MyComponent
}
},
})
Patch an object
import * as ots from 'odoo-typescript/v18.0'
ots.definePatch({
deps: { navbar: '@point_of_sale/app/navbar/navbar' },
objToPatch({navbar}) {
return navbar.Navbar.prototype
},
patch() {
return {
setup() {
super.setup()
console.log("Patching Navbar ...")
}
}
},
})
To enable auto-completion for custom modules you need to extend the interface Modules
.
import * as ots from 'odoo-typescript/v18.0'
const foo = ots.define({
name: '@mymodule/foo'
deps: {},
factory() {
// ...
}
}
declare module 'odoo-typescript/18.0' {
export interface Modules {
'@mymodule/foo': Awaited<typeof foo>
}
}