Skip to content

[no-undef] False positive with optional chaining #1116

Closed
@dannybloe

Description

@dannybloe

Hi there,

Just trying the latest eslint-plugin (2.4.0) with optional chaining and this code:

const a: { x: number; y: number; z?: number} = { x: 1, y: 2 };
const b = a?.z ?? 3;

console.log(b);

Gives a no-undef error on .z

module.exports = {
	'globals': {
		'Class': true,
		'SyntheticMouseEvent': true,
		'SyntheticChangeEvent': true,
		'TimeoutID': true,
		'IntervalID': true,
		'Blob': true
	},

	'extends': [
		'eslint-config-airbnb',
		'plugin:@typescript-eslint/recommended'
	],

	parser: '@typescript-eslint/parser',
	plugins: [
		'@typescript-eslint',
		'@typescript-eslint/eslint-plugin',
		'react'
	],

	'env': {
		'browser': true,
		'node': true,
		'es2017': true,
		'mocha': true
	},
	'rules': {
		'no-bitwise': 'off',
		'no-console': 'off',
		'spaced-comment': 'off',
		'no-param-reassign': 'off',
		'no-return-assign': 'warn',
		'no-nested-ternary': 'off',
		'no-restricted-globals': 'off',
		'class-methods-use-this': 'off',
		'sort-keys': 0,
		'indent': [
			'error',
			'tab',
			{
				'SwitchCase': 1
			}
		],
		'no-confusing-arrow': 'off',
		'implicit-arrow-linebreak': 'off',
		'lines-between-class-members': 'off',
		'prefer-destructuring': 'off',

		'arrow-body-style': 'off',
		'operator-linebreak': 'off',
		'no-underscore-dangle': 0,
		'no-tabs': 0,
		'no-shadow': 0,
		'no-useless-escape': 0,
		'padded-blocks': 0,
		'space-in-parens': 0,
		'template-curly-spacing': [
			'error',
			'always'
		],
		'object-curly-newline': 'off',
		'comma-dangle': [
			'error',
			'never'
		],
		'no-trailing-spaces': 'off',
		'no-unused-vars': 'warn',
		'no-unused-expressions': 'off',
		'linebreak-style': [
			'error',
			'unix'
		],
		'max-len': [
			'error',
			400,
			2,
			{
				'ignoreUrls': true,
				'ignoreComments': false,
				'ignoreRegExpLiterals': true,
				'ignoreStrings': true,
				'ignoreTemplateLiterals': true
			}
		],

		'import/prefer-default-export': 0,
		'import/no-unresolved': 0,
		'import/no-cycle': 'off',
		'import/no-extraneous-dependencies': 'off',
		'import/no-webpack-loader-syntax': 0,

		'react/prefer-stateless-function': 'off',
		'react/no-multi-comp': 'off',
		'react/jsx-boolean-value': 'off',
		'react/jsx-closing-tag-location': 'off',
		'react/jsx-closing-bracket-location': 'off',
		'react/jsx-curly-spacing': [
			'error',
			{
				'when': 'always'
			}
		],
		'react/jsx-filename-extension': [
			'warn',
			{
				'extensions': [
					'.ts',
					'.tsx'
				]
			}
		],
		'react/jsx-indent-props': [
			'error',
			'tab'
		],
		'react/jsx-one-expression-per-line': 'off',
		'react/jsx-indent': [
			'error',
			'tab'
		],
		'react/button-has-type': 'off',
		'react/no-unescaped-entities': 'off',
		'react/prop-types': 0,
		'react/require-default-props': 0,
		'react/destructuring-assignment': 'off',
		'react/sort-comp': 'off',
		'react/state-in-constructor': 'off',
		'react/static-property-placement': 'off',
		'react/no-array-index-key': 'off',

		'@typescript-eslint/class-name-casing': 'off',
		'@typescript-eslint/explicit-function-return-type': 'off',
		'@typescript-eslint/ban-ts-ignore': 'off',
		'@typescript-eslint/no-explicit-any': 'off',

		'jsx-a11y/anchor-is-valid': 'off',
		'jsx-a11y/click-events-have-key-events': 'off',
		'jsx-a11y/href-no-hash': 'off',
		'jsx-a11y/label-has-for': 'off',
		'jsx-a11y/mouse-events-have-key-events': 'off',
		'jsx-a11y/no-autofocus': 'off',
		'jsx-a11y/no-noninteractive-element-interactions': 'off',
		'jsx-a11y/no-noninteractive-tabindex': 'off',
		'jsx-a11y/no-static-element-interactions': 'off',
		'jsx-a11y/show-errors': 'off',
		'jsx-a11y/tabindex-no-positive': 'off'
	}
};

Versions

package version
@typescript-eslint/eslint-plugin 2.4.0
@typescript-eslint/parser 2..4.0
eslint-config-airbnb 18.0.1
TypeScript 3.7.0-beta
ESLint 6.5.1
node 10.16.2
npm 6.10.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghas prthere is a PR raised to close thispackage: eslint-pluginIssues related to @typescript-eslint/eslint-pluginscope analyserIssues that are caused by bugs/incomplete cases in the scope analyser

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions