Skip to content

"Unsafe member access" inside await blocks #534

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
2 tasks done
NatoBoram opened this issue Jul 4, 2023 · 1 comment · Fixed by sveltejs/svelte-eslint-parser#371
Closed
2 tasks done

"Unsafe member access" inside await blocks #534

NatoBoram opened this issue Jul 4, 2023 · 1 comment · Fixed by sveltejs/svelte-eslint-parser#371

Comments

@NatoBoram
Copy link

NatoBoram commented Jul 4, 2023

Before You File a Bug Report Please Confirm You Have Done The Following...

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.

What version of ESLint are you using?

^8.44.0

What version of eslint-plugin-svelte are you using?

^2.32.2

What did you do?

Configuration
module.exports = {
	root: true,
	extends: [
		'eslint:recommended',
		'plugin:@typescript-eslint/recommended',
		'plugin:@typescript-eslint/recommended-requiring-type-checking',
		'plugin:@typescript-eslint/strict',
		'plugin:svelte/recommended',
		'plugin:svelte/prettier',
		'prettier',
	],
	parser: '@typescript-eslint/parser',
	plugins: ['@typescript-eslint'],
	parserOptions: {
		sourceType: 'module',
		ecmaVersion: 2020,
		project: './tsconfig.eslint.json',
		extraFileExtensions: ['.svelte'],
	},
	env: {
		browser: true,
		es2017: true,
		node: true,
	},
	overrides: [
		{
			files: ['*.svelte'],
			parser: 'svelte-eslint-parser',
			parserOptions: {
				parser: '@typescript-eslint/parser',
			},
		},
	],
	rules: {
		'@typescript-eslint/consistent-type-exports': 'error',
		'@typescript-eslint/consistent-type-imports': 'error',
		'@typescript-eslint/default-param-last': 'error',
		'@typescript-eslint/method-signature-style': 'error',
		'@typescript-eslint/no-import-type-side-effects': 'error',
		'@typescript-eslint/prefer-readonly': 'error',
		'@typescript-eslint/promise-function-async': ['error', { checkArrowFunctions: false }],
		'@typescript-eslint/require-array-sort-compare': 'error',
		'@typescript-eslint/return-await': 'error',
		'@typescript-eslint/sort-type-constituents': 'error',
		'@typescript-eslint/switch-exhaustiveness-check': 'error',

		// SvelteKit uses that for returning errors in routes
		'@typescript-eslint/no-throw-literal': 'off',

		// Receiving markdown from the API
		'svelte/no-at-html-tags': 'off',
	},
}
<script lang="ts">
	import type { CommunityView } from 'lemmy-js-client'

	export let community: Promise<CommunityView>
	export let followCommunity: (follow: boolean) => Promise<void>
</script>

{#await community}
	<button class="rounded-full bg-surface px-4 py-2 text-on-surface">Loading...</button>
{:then community}
	{#if community.subscribed === 'NotSubscribed'}
		<button
			class="rounded-full border-surface-container bg-surface-container px-4 py-2 text-on-surface-container hover:bg-surface hover:text-on-surface"
			on:click={() => followCommunity(true)}
		>
			Join
		</button>
	{/if}
{/await}

What did you expect to happen?

Linting should pass

What actually happened?

/home/nato/Code/github.com/NatoBoram/Leanish/src/lib/SubscribeButton.svelte
  11:7  error  Unsafe member access .subscribed on an `any` value  @typescript-eslint/no-unsafe-member-access

 1 problem (1 error, 0 warnings)

Link to GitHub Repo with Minimal Reproducible Example

https://github.com/NatoBoram/bug-report-terrtc/commit/8c5c4c89aa1bb4e0a86cc8ef05c90b14dd7a53f5 (Deleted)

Additional comments

This happens when plugin:@typescript-eslint/recommended-requiring-type-checking is enabled

I think this can be worked around by changing the name of the variable after :then

@ota-meshi
Copy link
Member

Thank you for posting this issue.
Using the same name for #await and :then does not seem to work. To fix the problem we need to fix the parser.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants