Skip to content

Type annotation for object with unknown properties but known property types? #7803

Closed
@remojansen

Description

@remojansen

I have encounter a few times in multiple applications an scenario in which I don't know the properties of an object but I do know that all its properties are of a certain type.

For example:

interface Metadata {
  key: string,
  value: any
}

var metadata = {
  someReducer: Metadata ,
  anotherReducer: Metadata , 
  // ...
}

In this scenario:

  • I don't know the property names or number of properties of metadata
  • I do know that Metadata is the type of all the properties of metadata

Now let's imagine that a function take the metadata object as argument:

function doSomething(metadata: any) {
  // ...
}

I used any as the type of the argument metadata but It would be great if I could let developers know that all the properties of this object must be of type Metadata.

is there any way to create such type annotation?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions