Skip to content

Support exactOptionalPropertyTypes in tsconfig compilerOptions #2236

Open
@mrclrchtr

Description

@mrclrchtr

Description

When enabling exactOptionalPropertyTypes in tsconfig compilerOptions, I get warnings like:

TS2375: Type '{ username: string; displayName: string | undefined; }' is not assignable to type 'UserDto' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
  Types of property 'displayName' are incompatible.
    Type 'string | undefined' is not assignable to type 'string'.
      Type 'undefined' is not assignable to type 'string'. [plugin angular-compiler]

On the following code:

const userDto: UserDto = {
   username: user.username,
   displayName: user.displayName,
};

The generated type looks like:

export interface UserDto {
  displayName?: string;
  username: string;
}

A working type would look like:

export interface UserDto {
  displayName?: string | undefined;
  username: string;
}

Maybe relevant, but old issue: #590

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature 🚀New feature or requestprioritized 🚚This issue has been prioritized and will be worked on soon

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions