Skip to content

missing properties after applying spread operator on instance of abstract type  #32022

@paulluap

Description

@paulluap

TypeScript Version: 3.5.2

Search Terms:
spread operator type error, Object.assign,
Code

abstract class Base { 
    abstract get a(): string;
    abstract get b(): string;
}
class A extends Base{ 
    a: string
    b: string
}
const a1 : Base = new A() 
const a2 : Base = {...a1}  //reports error: Type '{}' is missing the following properties from type 'Base': a, bts(2739)

const a3 : Base = a1
const a4 : Base = Object.assign({}, a1)

Expected behavior:
code compiles

Actual behavior:
reports error on a2
Type '{}' is missing the following properties from type 'Base': a, bts(2739)

Playground Link:
https://www.typescriptlang.org/play/#src=abstract%20class%20Base%20%7B%20%0D%0A%20%20%20%20abstract%20get%20a()%3A%20string%3B%0D%0A%20%20%20%20abstract%20get%20b()%3A%20string%3B%0D%0A%7D%0D%0Aclass%20A%20extends%20Base%7B%20%0D%0A%20%20%20%20a%3A%20string%0D%0A%20%20%20%20b%3A%20string%0D%0A%7D%0D%0Aconst%20a1%20%3A%20Base%20%3D%20new%20A()%20%0D%0Aconst%20a2%20%3A%20Base%20%3D%20%7B...a1%7D%0D%0Aconst%20a3%20%3A%20Base%20%3D%20a1%0D%0Aconst%20a4%20%3A%20Base%20%3D%20Object.assign(%7B%7D%2C%20a1)

Related Issues:

Metadata

Metadata

Assignees

No one assigned

    Labels

    Design LimitationConstraints of the existing architecture prevent this from being fixed

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions