Skip to content

Default values of readonly parameter properties shouldn't have literal types #11409

Closed

Description

@falsandtru

TypeScript Version: master

Code

new class {
  constructor(
    n = 1,
    public readonly m = 2
  ) {}
}(3, 4);
$ node built/local/tsc.js -t es6 -m commonjs --noEmit index.ts
index.ts(6,6): error TS2345: Argument of type '4' is not assignable to parameter of type '2'.

Activity

  1. falsandtru commented on Oct 26, 2016

    @falsandtru
    ContributorAuthor

    I think this issue should be added milestone 2.1.

  2. changed the title [-]Default parameters shouldn't be inferred to literal types[/-] [+]Default values of readonly parameter properties shouldn't be treated as literal types[/+] on Oct 26, 2016
  3. changed the title [-]Default values of readonly parameter properties shouldn't be treated as literal types[/-] [+]Default values of readonly parameter properties shouldn't have literal types[/+] on Oct 26, 2016
  4. modified the milestones: TypeScript 2.1, , on Oct 27, 2016
  5. Andarist commented on Jan 8, 2023

    @Andarist
    Contributor

    Ryan Cavanaugh (@RyanCavanaugh) this works OK today, the issue can be closed

  6. locked as resolved and limited conversation to collaborators on Oct 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScript

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions