Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

219
Views
React typescript props not showing as possibly defined, even when I use '?' optional operator and '| undefined'

My linter seems to have stopped flagging possibly undefined properties passed into my React components. For example:

    interface BooleanTypeObject {
        prop1: true
    }
    
    interface MyComponentProps {
        disabledObject?: BooleanTypeObject | undefined;
    }
    
    export function MyComponent({
        disabledObject
    }: MyComponentProps): ReactElement {
    ...
    }

If I try to access prop1 within my component, I get no linter errors. But I do when the code is compiled if the disabledObject is undefined. I'm sure it used to work fine when I used the ? operator, or specified with | undefined.

I would have expected to see (parameter) disabledObject: BooleanTeeTypeObj | undefined here instead.

screenshot

All of my other linting seems to be working for typescript still. Can anyone think what's happening?

tsconfig.json

    {
        "compilerOptions": {
            "target": "ES2018",
            "module": "commonjs",
            "checkJs": false,
            "jsx": "react",
            "sourceMap": true,
            "strict": false,
            "noImplicitAny": false,
            "noUnusedLocals": false,
            "noUnusedParameters": false,
            "allowSyntheticDefaultImports": true,
            "esModuleInterop": true,
            "skipLibCheck": true,
            "forceConsistentCasingInFileNames": true
    }

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

This is because you have strictNullChecks: false. When it is set to false typescript ignores null and undefined entirely and BooleanTypeObject | undefined is equivalent to BooleanTypeObject. If you want typescript to shown an error, you need to set it to strictNullChecks: true https://www.typescriptlang.org/tsconfig#strictNullChecks

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!