odoo-typescript

2.1.0 • Public • Published

odoo-typescript

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

API

Aside from the type declarations odoo-typescript also includes some methods:

require

Import an existing module

import * as ots from 'odoo-typescript/v18.0'

const owl = ots.require('@odoo/owl')

define

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
        }
    },
})

definePatch

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 ...")
            }
        }
    },
})

Add type inference for custom modules

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>
  }
}

Package Sidebar

Install

npm i odoo-typescript

Weekly Downloads

15

Version

2.1.0

License

MIT

Unpacked Size

8.76 MB

Total Files

6619

Last publish

Collaborators

  • abichinger