Skip to content
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

Object is possibly 'undefined' while strictNullChecks is false? #35523

Closed
akafaneh opened this issue Dec 5, 2019 · 2 comments
Closed

Object is possibly 'undefined' while strictNullChecks is false? #35523

akafaneh opened this issue Dec 5, 2019 · 2 comments
Labels
Needs More Info The issue still hasn't been fully clarified

Comments

@akafaneh
Copy link

akafaneh commented Dec 5, 2019

TypeScript Version: 3.7.3

Search Terms:
Object is possibly 'undefined'.
create react app, CRA, create-react-app

Code

  public loadUserProfile = flow(function*(this: UserInfoStore) {
    this._isLoading = true;
    const getUserQuery = new GetUserProfileQuery();
    const profileInfo = yield this.dispatcher.send<Result<ProfileInfo>>(getUserQuery); 
    if (profileInfo && profileInfo.isError) {
      this._profileError = 'loadError';
      this._isLoading = false;
      return;
    }
    this._userInfo = profileInfo.data;
    this._isLoading = false;
  });

Expected behavior:
Compile without errors
Actual behavior:
Object is possibly 'undefined'. (this line if (profileInfo && profileInfo.isError) {
Playground Link: (not a playground but to state what tools i'm using) React, CRA, Mobx-React

Related Issues: #29642 ?

compilerOptions
"baseUrl": "./src",
"rootDir": "src/",
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"declaration": false,
"noImplicitAny": false,
"noImplicitReturns": true,
"removeComments": true,
"strictNullChecks": false,
"allowSyntheticDefaultImports": true,
"esModuleInterop": false,
"strict": true,
"forceConsistentCasingInFileNames": false,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"noEmit": true,
"jsx": "preserve",
"types": ["reflect-metadata", "node"],
"isolatedModules": true

More Details: I updated typescript to 3.7.3 after CRA released the scripts needed to support it "react-scripts": "3.3.0" and all worked fine and now I can use optional chaining and nullish coalescing but now I'm getting a compiling error that is stated above, though I'm checking for the object before accessing the key on it. and for some reason the "strictNullChecks": false in my tsconfig.json file is being ignored? the related issue states that there is something similar that is not fixed yet but my case is that with the strict checking turned off i still get such error.

Thanks.

@RyanCavanaugh RyanCavanaugh added the Needs More Info The issue still hasn't been fully clarified label Dec 5, 2019
@RyanCavanaugh
Copy link
Member

We need a self-contained repro to be able to look at these sorts of issues

@akafaneh
Copy link
Author

akafaneh commented Dec 6, 2019

@RyanCavanaugh understandable, i'm working on it to try to reproduce it in a stand alone repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs More Info The issue still hasn't been fully clarified
Projects
None yet
Development

No branches or pull requests

2 participants