# no-constructor-return

> Disallow returning a value from a constructor

If a constructor returns an object, `new` gives the caller that object instead of the new instance, so the result may not be an instance of the class. Returning a primitive such as a number is ignored, or throws a `TypeError` if the class extends another one.

A bare `return;` is allowed, so you can leave the constructor early.

{/* Generated by src/codegen/lint-rule-docs.ts. Do not edit this section. */}

## Configure

Off by default. To turn it on:

```toml bunfig.toml
[lint.rules]
"no-constructor-return" = "error" # or "warn"
```

{/* End of the generated section. */}

## Examples

Reported:

{/* bad */}
```js
class Connection {
  constructor(url) {
    if (cache.has(url)) {
      return cache.get(url);
    }
    this.url = url;
  }
}
```

Not reported:

{/* good */}
```js
class Connection {
  constructor(url) {
    this.url = url;
  }

  static open(url) {
    if (!cache.has(url)) {
      cache.set(url, new Connection(url));
    }
    return cache.get(url);
  }
}
```

{/* good */}
```js
class Timer {
  constructor(delay) {
    this.delay = delay;
    if (delay === 0) {
      return;
    }
    this.start();
  }
}
```
