Question: I have a Vue application which communicates with API (using axios requests) and return error(s).
It works fine if I get only one error, for example when response is like this: `{"error":"passwords.token"}`

When i'm getting cumulated errors like this: 

```
{"message":"The given data was invalid.",
 "errors":{
   "password":["The password confirmation does not match."]}
}

```

Here is my code of my Vue component and method resetPassword()

```
methods: {
        resetPassword () {
            this.$vs.loading()

            const payload = {
                userDetails: {
                    email: this.email,
                    password: this.password,
                    password_confirmation: this.password_confirmation,
                    token: this.token
                }
            }

            this.$store.dispatch('auth/resetPassword', payload)
                .then((response) => {
                    this.$vs.loading.close()
                    this.$vs.notify({
                        time: 10000,
                        title: 'Authentication Success',
                        text: response.message.data.message,
                        iconPack: 'feather',
                        icon: 'icon-success-circle',
                        color: 'success'
                    })
                })
                .catch(error => {
                    this.$vs.loading.close()
                    this.$vs.notify({
                        time: 6000,
                        title: 'Authentication Error',
                        text: error.message,
                        iconPack: 'feather',
                        icon: 'icon-alert-circle',
                        color: 'danger'
                    })
                })
        },
    },

```

Answer: 
What your are literally trying to do, introducing arbitrary scopes for types, can be accomplished via a *TypeScript* namespace.

```
declare namespace myNamespace {
  type IntermediaryType = {
    decisiveKey: true,
    mutatedKey: (params: any) => void,
  } | {
    decisiveKey: false,
    mutatedKey?: false,
  }

  interface IntermediaryType2 {
    foo?: string,
    bar?: boolean,
  }

  export type FinalType = IntermediaryType & IntermediaryType2;
}

const Foo = (param: myNamespace.FinalType) => {}

Foo({
  decisiveKey: true,
  mutatedKey: () => {},
});

```

However, if you are writing modern code, and therefore using modules, namespaces should almost always be avoided. Fortunately, if you're are using modules the solution is even simpler; don't export the intermediate types.

```
type IntermediaryType = {
  decisiveKey: true,
  mutatedKey: (params: any) => void,
} | {
  decisiveKey: false,
  mutatedKey?: false,
}

interface IntermediaryType2 {
  foo?: string,
  bar?: boolean,
}

export type FinalType = IntermediaryType & IntermediaryType2;

export const Foo = (param: FinalType) => {}

Foo({
  decisiveKey: true,
  mutatedKey: () => {},
});

```
I'm not sure about your preface

> 
> due to it's complexity, this type required the declaration of intermediary types
> 
> 
> 

this compiles

```
type FinalType = (
  | {
      decisiveKey: true;
      mutatedKey: (params: any) => void;
    }
  | {
      decisiveKey: false;
      mutatedKey?: false;
    }
) & {
  foo?: string;
  bar?: boolean;
};

const Foo = (param: FinalType) => {};

Foo({
  decisiveKey: true,
  mutatedKey: () => {}
});

```

Hope this helps.