Skip to content

[3.7] Mixin is broken with TypeScript 3.7 beta and compilerOptions.declaration = true #33739

Closed
@raymondfeng

Description

@raymondfeng

TypeScript Version: 3.7-beta

Search Terms:

Mixin declaration

Code

The issue can be reproduced with the following files:

  1. timestamp.ts
export type Constructor<T = {}> = new (...args: any[]) => T;

export function Timestamped<TBase extends Constructor>(Base: TBase) {
  return class extends Base {
    timestamp = Date.now();
  };
}
  1. user.ts
import { Timestamped } from './timestamp';

// Simple class
export class User {
  name = '';
}

// User that is Timestamped
export class TimestampedUser extends Timestamped(User) {
  constructor() {
    super();
  }
}
  1. tsconfig.json
{
  "$schema": "http://json.schemastore.org/tsconfig",
  "compilerOptions": {
    "skipLibCheck": true,
    "strict": true,

    "incremental": false,

    "lib": ["es2018"],
    "module": "commonjs",
    "moduleResolution": "node",
    "target": "es2017",
    "sourceMap": true,

    // declaration true fails the compilation
    "declaration": true,

    "outDir": "dist",
    "rootDir": "src"
  },
  "include": ["src"]
}

Expected behavior:

tsc -p tsconfig.json should be successful as TS 3.6.x does.

Actual behavior:

src/user.ts:9:38 - error TS4020: 'extends' clause of exported class 'TimestampedUser' has or is using private name '(Anonymous class)'.

9 export class TimestampedUser extends Timestamped(User) {
                                       ~~~~~~~~~~~~~~~~~


Found 1 error.

Playground Link:

Related Issues:

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions