How do I fix error TS1015: Parameter cannot have question mark and initializer?

If you look in the TypeScript Language Specification document you can find a wealth of detail about the language syntax.

Section 3.9.2 describes call signatures i.e. the syntax used to call functions and constructors etc.

Section 3.9.2.2 is specifically about the parameters associated with a call.

It defines optional parameters as:

AccessibilityModifieropt BindingIdentifierOrPattern ? TypeAnnotationopt

AccessibilityModifieropt BindingIdentifierOrPattern TypeAnnotationopt Initializer

We can see see that either using ‘?’ OR providing a default value Initializer will mark the parameter as being optional.

So to fix the compiler error you can simply remove the ‘?’ and leave the default value and it will remain as an optional parameter as you intend.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)