Microsoft/TypeScript

Regression: incorrect return type when disabled strictNullChecks

Open

#60.187 geöffnet am 10. Okt. 2024

Auf GitHub ansehen
 (0 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)TypeScript (6.726 Forks)batch import
Domain: check: Type InferenceHelp WantedPossible Improvement

Repository-Metriken

Stars
 (48.455 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 6T 17h) (9 gemergte PRs in 30 T)

Beschreibung

🔎 Search Terms

"ts7011", "strictnullchecks"

🕗 Version & Regression Information

  • This changed between versions 5.6.3 and 5.7.0-beta (also in 5.7.0-dev.20241010)

When disabled strictNullChecks in tsconfig.json error TS7011: Function expression, which lacks return-type annotation, implicitly has an T return type

⏯ Playground Link

https://www.typescriptlang.org/play/?strict=false&strictNullChecks=false&alwaysStrict=false&noEmitHelpers=true&noUnusedLocals=true&esModuleInterop=false&declaration=false&importHelpers=true&experimentalDecorators=true&target=6&module=6&suppressImplicitAnyIndexErrors=true&strictBuiltinIteratorReturn=true&ts=5.7.0-dev.20241010#code/CYUwxgNghgTiAEAzArgOzAFwJYHtXwHcsJgxZgAVHAJRAHMBRADwAcAKAZwC54OMYsqOgEoetRq3gAfeKmQQIAbgBQYPH3gx5IDvAC88ANoByKMYA08YwCNjAXQB0iaBgCyUdlogI9APkLEpORU4sye2sLSMoZ2wopAA

💻 Code

declare function wildcardToRegExp(s: string): RegExp | null;
const rules = ['a', 'b'].flatMap(rule => wildcardToRegExp(rule) || []); // if flatMap<RegExp> - no error

🙁 Actual behavior

TS7011: Function expression, which lacks return-type annotation, implicitly has an 'RegExp | any[]' return type.

🙂 Expected behavior

No error

Additional information about the issue

No response

Contributor Guide