Search code examples
typescripttypescript-types

Can you change from `type` to `interface`?


I have types/interfaces that describe my API:

export type AddFileRequestApi = FormData

export interface AddMessageRequestApi {
  text: string;
  date: string;
}

Can I change export type AddFileRequestApi = FormData to use interface? E.g. something like this:

export interface AddFileRequestApi extends FormData

Solution

  • Yes, just add an empty body at the end ({}), since the body part of an interface isn't optional; example (more here). But why? And why have a type that's just an alias for FormData?

    T.J. Crowder from the comments on the question