The value being passed as a parameter is a number, which cannot be assigned to a parameter expecting a Date type

I'm currently in the process of testing a function by passing a date as a parameter, but I seem to be encountering an issue that I can't quite figure out. When structured like this, it throws an error stating "Argument of type 'number' is not assignable to parameter of type 'Date'.":

import { Component, OnInit } from '@angular/core';
import { DamageAssessmentReportService } from 'src/app/damage-assessment-report.service';

@Component({
  selector: 'app-fa-daform',
  templateUrl: './fa-daform.component.html',
  styleUrls: ['./fa-daform.component.css']
})
export class FADAFormComponent implements OnInit {

  constructor(private damageAssessmentReportService : DamageAssessmentReportService) { }
  
  //assessmentDescription: string, author: string, reportDateTime: Date
  createNewDAReport(){
    this.damageAssessmentReportService.createDAReport('Testing1','Testing2', 2022-10-10).subscribe(()=>{

    })
  }

  ngOnInit(): void {
  }

}

When the code is modified to the following structure, the error changes to "Argument of type 'string' is not assignable to parameter of type 'Date'.ts(2345)":

import { Component, OnInit } from '@angular/core';
import { DamageAssessmentReportService } from 'src/app/damage-assessment-report.service';

@Component({
  selector: 'app-fa-daform',
  templateUrl: './fa-daform.component.html',
  styleUrls: ['./fa-daform.component.css']
})
export class FADAFormComponent implements OnInit {

  constructor(private damageAssessmentReportService : DamageAssessmentReportService) { }
  
  //assessmentDescription: string, author: string, reportDateTime: Date
  createNewDAReport(){
    this.damageAssessmentReportService.createDAReport('Testing1','Testing2', '2022-10-10').subscribe(()=>{

    })
  }

  ngOnInit(): void {
  }

}

Answer №1

generateReporting requires a Date object.

this.reportingService.generateReporting('Info1','Info2', new Date(2022, 3, 15)).subscribe(() => {
  ...
});

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

Locate and substitute `?php` and `?` in a given string

I am facing a challenge with inserting a large string of valid HTML code into the DOM, as the string also includes PHP code. When Chrome renders the code, it automatically comments out the PHP sections. The PHP code is encapsulated in <?php ... ?>, s ...

Combining two lists in immutable.js by flattening and zipping

When faced with two immutable lists, such as: const x = [5,6,7]; const y = [x,y,z,w]; Is there a straightforward method to combine/interleave them in order to obtain: const z = [5,x,6,y,7,z,w]; ...

using jquery, how can you send multiple parameters in an ajax request

Hello and welcome! I'm having trouble passing parameters through an ajax URL. I am attempting to send multiple data using the jQuery $.ajax method to my PHP script, but I can only pass a single data item when concatenating multiple data entries toget ...

What is the method for a JavaScript program to determine if a global property name has been defined according to the ECMA-262 standard

Imagine creating a function called checkIfEcmaGlobal which would return true for recognized names of ECMA-262 globals. $ node > checkIfEcmaGlobal('Array') true > checkIfEcmaGlobal('process') false What approach could be taken to ...

How to Divide a String at the Second-to-Last Instance of a Comma Using jQuery

Imagine having a string like this: var str = "xy,yz,zx,ab,bc,cd"; If you wish to split it at the second-to-last comma occurrence, resulting in: a = "xy,yz,zx,ab" b = "bc,cd" How can one accomplish this task? ...

Tips for positioning a button next to a text area

I am facing an issue with aligning my text area and button vertically on the same line. Despite my attempts, the button keeps getting pushed downwards. Can someone please provide me with a solution to align them properly? Thank you. Here is the HTML code ...

Loading an Angular application by sending an HTTP request to populate an array

After developing a simple shopping cart application using Angular 9, I faced an issue where I could only retrieve the product list by triggering a click event. The core functionality of my app involved sending an HTTP request to the server in order to fet ...

What is causing the consistent occurrences of receiving false in Angular?

findUser(id:number):boolean{ var bool :boolean =false this.companyService.query().subscribe((result)=>{ for (let i = 0; i < result.json.length; i++) { try { if( id == result.json[i].user.id) ...

Exploring the use of a customizable decorator in Typescript for improved typing

Currently, I am in the process of creating TypeScript typings for a JavaScript library. One specific requirement is to define an optional callable decorator: @model class User {} @model() class User {} @model('User') class User {} I attempted ...

Exclusive Modal Pop-Up for First-Time Visitors - Utilizing Bootstrap, PHP, and JavaScript

Seeking assistance from the community as I have exhausted my online research efforts. I am currently working on implementing a welcome bootstrap modal in a php environment. Despite being new to php and js, I have managed to make it pop up only once using ...

Extract information from a JSON file and import it into an Angular TypeScript file

How can I retrieve data from a JSON file and use it in an Angular typescript file for displaying on web pages? this.http.get<any>('http://localhost:81/CO226/project/loginResult.json').subscribe((res: Response)=>{ }); Here ...

Converting a JSON array into a TypeScript array

Looking to convert a JSON array into a TypeScript variable array. The JSON data retrieved from http://www.example.com/select.php: { "User":[ {"Name":"Luca M","ID":"1"}, {"Name":"Tim S","ID":"2"}, {"Name":"Lucas W","ID":"3"} ...

Using Javascript with AngularJS to integrate with the Leaflet library for translation

I come across the same kind of statement every time I search the internet or read about leaflet, for example : var map = L.mapbox.map('map', { zoomControl:false }); What does this mean? And how can I incorporate it into Angularjs? P.S. : html ...

Full-screen mobile menu with sliding animation

I currently have a slide-out menu on my webpage, which is 350px wide let menuGeneral = $('#menu-general'); $('#menu-up-control').click(function () { menuGeneral.animate({ right: '0' }, 500); }); $(&a ...

Is there a way to access the HTML and CSS source code without using the inspect feature

I'm working on a project that involves an "edit box" where users can write text, add emojis, change the background color, insert images, and more. After users finish creating their content, I want them to be able to send it via email. This means I ne ...

Creating a React Native project without the use of TypeScript

Recently I dived into the world of React Native and decided to start a project using React Native CLI. However, I was surprised to find out that it uses TypeScript by default. Is there a way for me to create a project using React Native CLI without TypeS ...

Using PHP with the CodeIgniter framework, learn how to use Javascript to delete specific values in an HTML table row

Within my CodeIgniter project, I have a table that is being dynamically generated by Ajax. Each row in the table has a button to delete the corresponding entry from both the HTML table and the MySQL table. I have already found a way to remove the HTML tab ...

The 'each' method in Jquery cannot be used on a DOM that has been dynamically loaded using Ajax

Trying to refresh a Google advertisement located within divs that all share a common CSS class called 'adslot'. Some of these divs are loaded via ajax. However, upon document ready, using the jQuery each function only applies to the divs that wer ...

Can someone help me extract a specific portion and display the dimensions of the area?

In order for the mouse to create a selection range, simply release the mouse after making your selection. The selected area will display the values of width and height on both the X-axis and Y-axis in the designated fields. I am facing this issue and woul ...

What is the best way to find out which tab is currently active?

Struggling with Bootstrap 5, I found it challenging to retrieve the activated tab. Even after consulting their documentation, I only managed to obtain the ID of the first button and nothing more. var tabEl = document.querySelector('button[data-bs-t ...