0

The type in the constructor has two default values active or finished. But I think there should be a parameter type such as number or string.

Any explanation about this?

class ProjectList{
    templateElement: HTMLTemplateElement;

    constructor(private type: 'active' | 'finished'){
    
    }
}
2
  • 2
    The parameter type is 'active' | 'finished'. It's not a default value - it's that those are the only two possible arguments the function can be provided with. number or string would both be outside the permitted values. Commented Mar 18, 2022 at 3:22
  • 1
    See Literal Types and scroll down to "literal unions" Commented Mar 18, 2022 at 3:26

1 Answer 1

0

You are declaring that type is a string restricted to only possible 2 values. A default can also be declared, like this:

class ProjectList{
    templateElement: HTMLTemplateElement;

    constructor(private type: 'active' | 'finished' = 'active'){
    
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.