Skip to content

TypeError: Cannot read properties of undefined (reading 'type') #15916

@Mozartuss

Description

@Mozartuss

Prettier 3.2.1
Playground link

--parser typescript

Input:

    const randomFuncion = (value): void => {
        if (value.a) {
            funcA(
                "",
                funcB(
                    dayjs(value.a?.toString())
                  		.add(1, "day")
                  		.toISOString()
                )
            );
        }
    };

Output:

TypeError: Cannot read properties of undefined (reading 'type')
    at Jn (https://prettier.io/lib/plugins/estree.js:7:16595)
    at be (https://prettier.io/lib/plugins/estree.js:9:605)
    at be (https://prettier.io/lib/plugins/estree.js:10:209)
    at https://prettier.io/lib/plugins/estree.js:36:14282
    at Array.every (<anonymous>)
    at https://prettier.io/lib/plugins/estree.js:36:14273
    at Array.some (<anonymous>)
    at Oi (https://prettier.io/lib/plugins/estree.js:36:14252)
    at Kr (https://prettier.io/lib/plugins/estree.js:36:14852)
    at da (https://prettier.io/lib/plugins/estree.js:36:58423)

Expected output:

const randomFuncion = (value): void => {
  if (value.a) {
    funcA(
      "", 
      funcB(dayjs(value.a?.toString())
        .add(1, "day")
        .toISOString()
      )
    );
  }
};

Why?
That was not an Error in 3.1.1 here the error in version 3.2.0 which should be fixed in #15912

If I remove the question mark behind the funcB(dayjs(value.a? ... the error is gone.

Metadata

Metadata

Assignees

No one assigned

    Labels

    lang:javascriptIssues affecting JSlocked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions