1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

Strange behaviour with typescript function arguments coming from variable

Discussão em 'Angular' iniciado por jsadev.net, Maio 20, 2025.

  1. jsadev.net

    jsadev.net Guest

    I have an strange case here using Ionic Angular.

    I have a function inside a service with two arguments:

    async getTaskById(mobileTaskId: string, pushIntoTaskList?: boolean) {
    const task = await this.database.mobileTaskRepository
    .createQueryBuilder('task')
    .where('task.mobileTaskId = :id', {id: mobileTaskId})
    .getOne() || undefined;

    if(!task) return undefined;

    if(pushIntoTaskList) {
    const filterDates = new AmTaskFilterDates();

    if(!task.archived) {
    if(!task.plannedToDate || new Date(task.plannedToDate) < filterDates.now) {
    this.updateTaskList(this.taskListOverdue, this.taskListOverdue$, [task], true).then();
    }

    if(task.plannedToDate && new Date(task.plannedToDate) >= filterDates.startOfToday && new Date(task.plannedToDate) < filterDates.endOfToday) {
    this.updateTaskList(this.taskListToday, this.taskListToday$, [task], true).then();
    }

    if(task.plannedToDate && new Date(task.plannedToDate) >= filterDates.startOfThisWeek && new Date(task.plannedToDate) < filterDates.endOfThisWeek) {
    this.updateTaskList(this.taskListThisWeek, this.taskListThisWeek$, [task], true).then();
    }

    if(task.plannedToDate && new Date(task.plannedToDate) >= filterDates.endOfThisWeek && new Date(task.plannedToDate) < filterDates.endOfNextWeek) {
    this.updateTaskList(this.taskListNextWeek, this.taskListNextWeek$, [task], true).then();
    }

    if(task.plannedToDate && new Date(task.plannedToDate) >= filterDates.endOfNextWeek) {
    this.updateTaskList(this.taskListUpcoming, this.taskListUpcoming$, [task], true).then();
    }
    } else {
    this.updateTaskList(this.taskListArchived, this.taskListArchived$, [task], true).then();
    }
    }

    return task;
    }


    inside an component I call this function, but here the magic happens.

    if I do:

    const test = 'test';
    await this.mobileTaskService.getTaskById(test, true);


    the first param (mobileTaskId) is ignored and the second param is used as mobileTaskId -> pushIntoTaskList gets undefined.

    if I do:

    await this.mobileTaskService.getTaskById('test', true);


    or

    await this.mobileTaskService.getTaskById(`${test}`, true);


    its working... Does anyone have an idea why this could happen?

    here is also a screenshot of my IDE:

    [​IMG]

    Continue reading...

Compartilhe esta Página