Skip to content

Constant

@tsed/di

Usage

typescript
import { Constant } from "@tsed/di";

See /packages/di/src/types/common/decorators/constant.ts.

Overview

ts
function Constant<Type = unknown>(expression: string, defaultValue?: Type): PropertyDecorator;

Description

Return value from Configuration.

Example

typescript
import {Env} from "@tsed/core";
import {Constant, Value} from "@tsed/di";

export class MyClass {

   @Constant("env")
   env: Env;

   @Value("swagger.path")
   swaggerPath: string;

   @Value("swagger.path", "defaultValue")
   swaggerPath: string;

   constructor() {
      console.log(this.swaggerPath) // undefined. Not available on constructor
   }

   $onInit() {
     console.log(this.swaggerPath)  // something
   }
}

Released under the MIT License.