Skip to content

Possibly undefined but it's not #19415

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mbayou opened this issue Oct 23, 2017 · 3 comments
Closed

Possibly undefined but it's not #19415

mbayou opened this issue Oct 23, 2017 · 3 comments
Labels
Design Limitation Constraints of the existing architecture prevent this from being fixed

Comments

@mbayou
Copy link

mbayou commented Oct 23, 2017

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'."

@Ghabriel
Copy link

See #9998 .

@mhegazy mhegazy added the Design Limitation Constraints of the existing architecture prevent this from being fixed label Oct 23, 2017
@mhegazy
Copy link
Contributor

mhegazy commented Oct 23, 2017

also see #16546 and #9655

@mhegazy
Copy link
Contributor

mhegazy commented Nov 7, 2017

Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

@mhegazy mhegazy closed this as completed Nov 7, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Design Limitation Constraints of the existing architecture prevent this from being fixed
Projects
None yet
Development

No branches or pull requests

3 participants