How to get "add missing properties" suggestion when creating an anonymous object literal in VSCode and Typescript

668 Views Asked by At

Given a Typescript interface Foo, which has a property which is of interface Bar:

export interface Foo{
   bar:Bar;
}

export interface Bar{
  text:String;
}

when creating an object conforming to that interface VSCode will give me a suggestion to autocomplete missing properties:

var foo : Foo = {
}

becomes:

var foo : Foo = {
  bar: undefined
}

Now I would like to define the bar property:

var foo : Foo = {
  bar: {}
}

and VSCode gives me a warning: Property 'text' is missing in type '{}' but required in type 'Bar

but does not offer an option to create the missing property for me, as it did before.

Can I get this to work somehow? Or does this autocomplete feature only work when defining a named variable with declared type? This would be very useful for large, deeply nested interfaces.

0

There are 0 best solutions below