You are given a function `validateEmail(email: string): boolean` that takes an email address as a parameter and returns `true` if the email address is valid, and `false` otherwise. Your task is to implement a new function `filterEmails(emails: string[]): string[]` that takes an array of email addresses and returns a new array containing only the valid email addresses. The function should also throw an exception if any of the email addresses contain special characters or numbers. Write the function `filterEmails(emails: string[]): string[]` to solve this task.

**Function Signature:** `filterEmails(emails: string[]): string[]`

**Input**
- The `emails` parameter is an array of strings representing email addresses.

**Output**
- The function should return a new array containing only the valid email addresses.
- If any of the email addresses contain special characters or numbers, the function should throw an exception.

**Example**
```javascript
filterEmails(["john@gmail.com", "jane@gmail.com", "test123", "test!@#$"]) => ["john@gmail.com", "jane@gmail.com"]
filterEmails(["test1@", "test2@", "test3@"]) => throws an exception
```
user
Sure, here's how you could implement the `filterEmails` function in TypeScript, assuming you have a `validateEmail` function defined elsewhere in your code that meets the requirements you've outlined.

```typescript
function validateEmail(email: string): boolean {
  // Your implementation here
}

function filterEmails(emails: string[]): string[] {
  const filteredEmails: string[] = [];

  for (const email of emails) {
    if (email.includes(' ')) {
      throw new Error('Email address cannot contain spaces.');
    }

    if (validateEmail(email)) {
      filteredEmails.push(email);
    }
  }

  return filteredEmails;
}
```

Note that this implementation assumes that you'd like to throw an error if an email address contains spaces. If you'd like to handle this case differently (e.g. Remove spaces, replace with ""), you could modify the first `if` statement accordingly. Also, this implementation doesn't specifically check for special characters and numbers - it simply checks that the email is valid according to your `validateEmail` function. If you need more specific filtering, you could modify this `for` loop to check for specific characters or patterns.
assistant
You are given a function `validateEmail(email: string): boolean` that takes an email address as a parameter and returns `true` if the email address is valid, and `false` otherwise. Your task is to implement a new function `filterEmails(emails: string[]): string[]` that takes an array of email addresses and returns a new array containing only the valid email addresses. The function should also throw an exception if any of the email addresses contain special characters or numbers. Write the function `filterEmails(emails: string[]): string[]` to solve this task.

**Function Signature:** `filterEmails(emails: string[]): string[]`

**Input**
- The `emails` parameter is an array of strings representing email addresses.

**Output**
- The function should return a new array containing only the valid email addresses.
- If any of the email addresses contain special characters or numbers, the function should throw an exception.

**Example**
```javascript
filterEmails(["john@gmail.com", "jane@gmail.com", "test123", "test!@#$"]) => ["john@gmail.com", "jane@gmail.com"]
filterEmails(["test1@", "test2@", "test3@"]) => throws an exception
```
user
Sure, here's a possible implementation of the `filterEmails` function in TypeScript. This implementation assumes that the `validateEmail` function is already defined and works correctly. It also checks for special characters or numbers using a regular expression.

```typescript
function filterEmails(emails: string[]): string[] {
  // Assuming validateEmail function is already defined
  const validateEmail = (email: string): boolean => {
    // Your validation logic here
    return true; // or false
  };

  const regex = /^[a-zA-Z]+@[a-zA-Z]+\.[a-zA-Z]+$/; // Regular expression to match only alphabets, '@' and '.'

  const validEmails: string[] = [];

  for (const email of emails) {
    if (!regex.test(email)) {
      throw new Error('Invalid character in email');
    }

    if (validateEmail(email)) {
      validEmails.push(email);
    }
  }

  return validEmails;
}
```

This function first checks if the email contains any special characters or numbers using the `regex.test(email)` method. If it does, it throws an exception. If the email passes this check, it then checks if the email is valid using the `validateEmail` function. If the email is valid, it adds it to the `validEmails` array. Finally, it returns the `validEmails` array.
assistant