1
Hello, I have the following situation:
// essa classe contém apenas 2 propriedades
interface Foo {
a: string;
b: number;
}
// em determinada situação, eu preciso declarar
// a interface junto com mais uma propriedade, assim
let Bar: ({ c: boolean } implements Foo); // não funciona
let Bar: { c: boolean } implements Foo; // não funciona
let Bar: { c: boolean } implements Foo; // não funciona
let Bar: { c: boolean } && Foo; // não funciona
let Bar: [{ c: boolean } implements Foo]; // não funciona
let Bar: [{ c: boolean } && Foo]; // não funciona
the only way I understand that it is possible for me to do this would be to declare the interface again Bar
thus
interface Foo {
a: string;
b: number;
}
interface Bar extends Foo {
c: boolean;
}
let Bar:Bar;
Is there any way to extend the properties of a type in the statement (without the need to create an external interface? I do not believe it is fully functional I make the declaration of a new interface that does this only to meet this situation.
It doesn’t work because this syntax doesn’t make any sense and doesn’t do what you want, it’s an invention, it’s not that it doesn’t allow you to extend the type.
– Maniero
@Maniero, yes his statement does not exist, but has a correct syntax for it, as I presented in the reply, although I have never used, I prefer to declare an extended interface.
– Fernando Leal
@Fernandoleal yours is correct, I just don’t know if it solves what he wants.
– Maniero