mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
142b69823f
Before this commit, Env was an indexed type, this means that one could
write env.anything, and it would accept it as a valid type. This is
actually quite dangerous, because we lose the typing advantages for all
keys that are properly defined.
For example, if a component is defined as:
class MyComponent extends Component<Props> {
...
}
Then Typescript will let it use anything from the environment, even if
it is wrong. So, most properly typed Typescript applications should use
instead a sub environment:
interface MyAppEnv extends Env {
someKey: someValue
}
Then, the component should be defined this way:
class MyComponent extends Component<Props, MyAppEnv> {
...
}
Before this commit, any typos in the environment accesses would not be
noticed by typescript.
20 lines
544 B
TypeScript
20 lines
544 B
TypeScript
import { Component } from "../component/component";
|
|
import { xml } from "../tags";
|
|
import { EnvWithRouter } from "./router";
|
|
|
|
export class RouteComponent extends Component<{}, EnvWithRouter> {
|
|
static template = xml`
|
|
<t>
|
|
<t
|
|
t-if="routeComponent"
|
|
t-component="routeComponent"
|
|
t-key="env.router.currentRouteName"
|
|
t-props="env.router.currentParams" />
|
|
</t>
|
|
`;
|
|
|
|
get routeComponent(): any {
|
|
return this.env.router.currentRoute && this.env.router.currentRoute.component;
|
|
}
|
|
}
|