Deno is facing an issue where the reflection metadata regarding 'design:paramtypes' is coming back as undefined

I've been working on implementing dependency injection in TypeScript using Deno, but I've encountered a problem with the

Reflect.getMetadata('design:paramtypes', ...)
method, as it's returning an undefined value and I'm not sure why.

Deno 1.6.0
Ubuntu 18.04.5 LTS

The Reflect file I'm using is located here: https://github.com/edualb/dependencyInjectionPOC/blob/main/Reflect.ts

tsconfig.json

{
  "compilerOptions": {
    "target": "ES2020",
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "lib": ["es5", "es6", "dom"],
  }
}

Code

decorator.ts

export interface Type<T> {
    new(...args: any[]): T;
}

export function Injectable(): (target: Type<any>) => void {
    return (target: Type<any>) => {}
}

service2.ts

import { Injectable } from './decorator.ts';

@Injectable()
export class Service2 {
    constructor() {}
}

service.ts

import { Injectable } from './decorator.ts';
import { Service2 } from './service2.ts';

@Injectable()
export class Service {
    constructor(private s2: Service2) {}
}

main.ts

import { Reflect } from './Reflect.ts';
import { Service } from './service.ts';

console.log(Reflect.getMetadata('design:paramtypes', Service)) // this line is giving me undefined

Command used to execute:

$ deno run main.ts

Github repository: https://github.com/edualb/dependencyInjectionPOC

Can anyone provide assistance with this issue?

Answer №1

For further information, please visit https://deno.land/[email protected]/advanced/typescript/configuration :

The recommendation is to utilize deno.json in place of tsconfig.json ...

An example showcasing the usage of deno.json :

{    
  "compilerOptions": {
    "emitDecoratorMetadata": true,
    "jsx": "react-jsx",
    "jsxImportSource": "preact"
  }
}

Once implemented, statements like

Reflect.getMetadata("design:type", target, key);
will function correctly.

Answer №2

Successfully resolved the problem by including the tag -c / --config in the command line:

$ deno run -c tsconfig.json main.ts

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best method to display a service property within a controller?

If we consider the scenario where I have a controller named ctrlA with a dependency called serviceB, which in turn has a property known as propertyC. My development environment involves Angular and Typescript. When interacting with the user interface, the ...

Leveraging the Typescript Compiler API for transforming a typescript document

I am currently exploring the Typescript Compiler API to develop a tool that merges typescript files. I am curious if there is a way to: Modify the AST after parsing a .ts file. Convert the modified AST back into a .ts file. I have reviewed the documenta ...

Tips for creating a state change function using TypeScript

Imagine the temperature remains constant for 20 minutes, but at the 21st minute, it changes. The state change is determined by a programmable state change function. How can I create a function to calculate the difference in state change? if(data.i ...

Determine element height in Angular 5 by clicking on it

Currently, I am experimenting with determining the height of an element that I click on within a sidebar. The purpose is to display submenus accordingly. Below is the code snippet that I am working on: <li (click)="newsExpanded = !newsExpanded; getMarg ...

Access exclusive content by subscribing now!

How can I return a reference to a subject from a service without allowing the receiver to call .next() on the subject? Let's say there is a service with a subject that triggers new events. class ExampleService { private exampleSubject = new Subjec ...

Angular HttpInterceptor failing to trigger with nested Observables

Utilizing a HttpInterceptor is essential for adding my Bearer token to all calls made to my WebApi. The interceptor seamlessly functions with all basic service calls. However, there is one specific instance where I must invoke 2 methods and utilize the re ...

Utilizing the async pipe with an RxJS interval on a component that is dynamically generated: A step-by

Is it possible to use the async pipe with RxJS interval() on dynamically created components, as shown in this example? When applying the async pipe inside the component, the interval is often ignored when components change. For instance, if I want to retr ...

The type of a reference variable in a type definition of another variable

Can we reference the type of one variable (let's call it someVar) in TypeScript when declaring the type of another variable (anotherVar)? For example, instead of creating a separate type declaration for { complex: 'type' }, can we directly ...

The chaos of Typescript decorators

Are there any strategies for managing extensive decorator usage within classes? Consider this instance of a class property in my NestJS application, featuring an incomplete swagger documentation decorator: @ApiModelProperty({ description: 'des ...

Incorporating debounce functionality in React text input using lodash throttle and Typescript

I've been having trouble getting this text input throttle to function properly in my React project, despite spending a considerable amount of time reading documentation. import { throttle } from 'lodash'; ... <input type="t ...

Tips for utilizing the @Component decorator in both abstract classes and their implementations within Angular 8

While working with Angular 8, I am attempting to utilize abstract components. My goal is to define the templateUrl and styleUrls in my abstract class, but have the selector name specified in the implemented class. Here is an example: @Component({ // sel ...

Jest fails to pass when encountering tsx syntax errors

Currently, I am incorporating jest tests into my project. The project is comprised of both TypeScript (.ts) and TypeScript JSX (.tsx) files. Below is a snippet from my jest.config.js file. module.exports = { preset: "ts-jest", testEnvironment: "jsdom" ...

What is the best way to generate a random item when a button is clicked?

I'm currently working on a feature in my component that generates a random item each time I access the designated page. While the functionality is set to automatically refresh and showcase a new random item, I am now looking to trigger this action man ...

React-Testing-Library - MatchingFunction represented as text

screen.getByText(match: Matcher) requires a Matcher that can be of type string, RegExp, or MatcherFunction. If using the latter, it should be of the form (content: string, element: HTMLElement) => boolean. Expectation: screen.getByText((content, elemen ...

Conceal the PayPal Button

Currently, I'm facing a challenge where I need to dynamically show or hide a PayPal button based on the status of my switch. The issue is that once the PayPal button is displayed, it remains visible even if the switch is toggled back to credit card pa ...

Rxjs: accessing the most recent value emitted by an observable

As shown in the demo and indicated by the title const { combineLatest, interval, of } = rxjs; const { first, last, sample, take, withLatestFrom } = rxjs.operators; const numbers = interval(1000); const takeFourNumbers = numbers.pipe(take(4)); takeFourNu ...

Can a universal type be designed for application across various types?

I've got this function: function stackPlayer(stack){ } The stack parameter can have one of the following forms only: a function that takes req, res, and next as arguments. a function that takes req, res, and next as arguments, and returns a functio ...

Discovering the country associated with a country code using ngx-intl-tel-input

In my application, I am trying to implement a phone number field using this StackBlitz link. However, I have observed that it is not possible to search for a country by typing the country code (e.g., +231) in the country search dropdown. When I type a coun ...

Component in Next.js fetching data from an external API

I am attempting to generate cards dynamically with content fetched from an API. Unfortunately, I have been unsuccessful in finding a method that works during website rendering. My goal is to pass the "packages" as properties to the component within the div ...

Form validation errors were detected

Currently, I am working with a formgroup that contains input fields with validations set up in the following manner: <mat-form-field class="mat-width-98" appearance="outline"> <mat-label>Profession Oc ...