Code below
enum Type { digit=1, alpha=2, alnum=3 }
enum Transform{uppercase=1,lowercase}
interface Options {
type: Type;
length: number;
min: number;
max: number;
uppercase: boolean;
lowercase: boolean;
transform: Transform;
valueChange: (element:Object,value:string) => string;
}
class InputFilter {
constructor(private options: Options, private element: Object) {
}
}
I wanna to makeoptionshave defaulte value,like this:
options = {
"type": "alnum",
"length": null,
"min": 0,
"max": Infinity,
"uppercase": true,
"lowercase": true,
"transform": null,
"valueChange": function(element, value) {}
};
How can I do?Wating online :).
Hi @codelegant, you could have both a type annotation and an initializer for your parameter property:
class InputFilter {
constructor(private options: Options = {
type: "alnum",
length: null,
min: 0,
max: Infinity,
uppercase: true,
lowercase: true,
transform: null,
valueChange(element, value) {}
},
private element: {}) {
}
}
Or you could make Options a class:
class Options {
type = "alnum";
length = null;
min = 0;
max = Infinity;
uppercase = true;
lowercase = true;
transform = null;
valueChange(element, value) { }
}
class InputFilter {
constructor(private options = new Options(),
private element: {}) {
}
}
However, in the future, any questions that are not about whether there is a bug in the compiler should probably be posted on StackOverflow.
my solution
export class Doctors{
constructor(
name= "Ali 艦en",
photo= "http://res.cloudinary.com/doctor.svg",
cv= "Ozgecmis kisaca"
){ }
}
export class Corporate{
constructor(
doctors:Doctors[] = [new Doctors()]
)
{ }
Most helpful comment
Hi @codelegant, you could have both a type annotation and an initializer for your parameter property:
Or you could make
Optionsa class:However, in the future, any questions that are not about whether there is a bug in the compiler should probably be posted on StackOverflow.