Skip to content

Possibly undefined but it's not #19415

Closed
Closed
@mbayou

Description

@mbayou

Hi,

I have an issue about the strictNullChecks, indeed I am using it right now and it says "Object is possibly 'undefined'." on an object cannot be undefined.

TypeScript Version: 2.5.3

Code

Failling code

// Retrieve circle with identifier
const circle: Circle | undefined = await this.circleDao.findById(command.getId());
// Check if localAuthority is found in database
Utils.checkArgument(circle !== undefined, "Circle with id '" + command.getId() + "' cannot be found");

// Compiler fail on this line with message "Object is possibly 'undefined'."
circle.setDefaultCircle(command.isDefaultCircle());

Utils.ts method

public static checkArgument(expression: boolean, message?: string) {
        if (!expression) {
            throw new IllegalArgumentError(message);
        }
}

Expected behavior:

When I check if an object is undefined in an external method the compiler can see it and don't throw error : "Object is possibly 'undefined'."

Actual behavior:

When I check if an object is undefined in an external method the compiler throw error : "Object is possibly 'undefined'."

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