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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悰 Bug: strictNonNullAssertions changes "return undefined" to "return undefined!" #1516

Open
3 tasks done
rubiesonthesky opened this issue Apr 3, 2024 · 1 comment
Open
3 tasks done
Labels
status: accepting prs Please, send a pull request to resolve this! 馃檹 type: bug Something isn't working :( 馃悰

Comments

@rubiesonthesky
Copy link
Collaborator

Bug Report Checklist

  • I have tried restarting my IDE and the issue persists.
  • I have pulled the latest main branch of the repository.
  • I have searched for related issues and found none that matched my issue.

Expected

It should allow returning undefined here

const collectFileNamesFromGlobs = async (
	argv: TypeStatArgv,
	cwd: string,
	include: readonly string[] | undefined,
): Promise<[readonly string[], readonly string[]] | undefined> => {
	if (argv.args.length) {
		return [argv.args, await glob(argv.args)];
	}

	if (include === undefined) {
		return undefined;
	}

	return [
		include,
		await glob(include.map((subInclude) => path.join(cwd, subInclude))),
	];
};

Actual

The undefined return is changed to this

	if (include === undefined) {
		return undefined!;
	}

Additional Info

This is probably related to #1494 - it does not understand that the function accepts return type Promise<undefined>.

typestat.json

[
    {
        "fixes": {
            "strictNonNullAssertions": true
        },
        "include": [
            "src/**/*.{ts,tsx}"
        ],
        "projectPath": "./tsconfig.json",
        "types": {
            "strictNullChecks": true
        }
    }
]

tsconfig

{
	"compilerOptions": {
		"declaration": true,
		"declarationMap": true,
		"esModuleInterop": true,
		"module": "NodeNext",
		"moduleResolution": "NodeNext",
		"noEmit": true,
		"outDir": "lib",
		"resolveJsonModule": true,
		"skipLibCheck": true,
		"sourceMap": true,
		"strict": true,
		"target": "ES2022"
	},
	"include": ["src", "test/*.ts"]
}
@rubiesonthesky rubiesonthesky added the type: bug Something isn't working :( 馃悰 label Apr 3, 2024
@rubiesonthesky
Copy link
Collaborator Author

These work correctly in test setup, so I suspect that the issue is with returning Promise

const lambdaGivenUndefinedReturnsUndefined = (): string | undefined => {
  return undefined;
};

const lambdaGivenNullReturnsNull = (): string | null => {
  return null;
};

@rubiesonthesky rubiesonthesky added the status: accepting prs Please, send a pull request to resolve this! 馃檹 label Apr 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: accepting prs Please, send a pull request to resolve this! 馃檹 type: bug Something isn't working :( 馃悰
Projects
None yet
Development

No branches or pull requests

1 participant