Answer the question
In order to leave comments, you need to log in
How does typescript compare declared types?
interface SStitle {
title: string;
}
const x:SStitle = { title: "AZ5"};
if(???){...}esle{...} //x === SStitle
Answer the question
In order to leave comments, you need to log in
Typescript does not exist in runtime, bare js remains, i.e. such a check will not work
Or do a check on indirect signs, such as
function isSStitle(arg: any): arg is SStitle {
return arg && typeof arg.title === 'string';
}
class SStitle {
title: string;
constructor(title: string) {
this.title = title;
}
}
const x:SStitle = new SStitle("AZ5");
if(x instanceof SStitle){...}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question