Skip to content

Passing object with readonly fields to function expecting modifiable fields does not give a type error #11180

Closed
@paulkoerbitz

Description

@paulkoerbitz

TypeScript Version: 2.0.3, 2.1.0-dev.20160927

Code

// A *self-contained* demonstration of the problem follows...
'use strict';

interface RO { readonly x: number; }
interface RW { x: number; }

const ro: RO = Object.freeze({ x: 3 });

function modifyX(input: RW) {
    input.x = 5;
}

// No type error
// Throws exception
modifyX(ro);

Expected behavior:
The call modifyX(ro) should give a type error, as ro has a readonly property but the interface to modifyX requires a modifiable field.

Actual behavior:
No type error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Design LimitationConstraints of the existing architecture prevent this from being fixed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions