microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
100.59k stars 12.44k forks source link

[5.7-beta][isolatedDeclarations][regression] Missing explicit type annotation false positive #60192

Open MichaelMitchell-at opened 3 hours ago

MichaelMitchell-at commented 3 hours ago

๐Ÿ”Ž Search Terms

explicit type annotation false positive isolated declarations

๐Ÿ•— Version & Regression Information

โฏ Playground Link

https://www.typescriptlang.org/dev/bug-workbench/?target=7&noCheck=true&isolatedDeclarations=true&emitDeclarationOnly=true&ts=5.7.0-dev.20241010#code/PTAEAEGcBcCcEsDG0Bco4FcCmAoEEATLRAGwENYzp4B7AOzU133DpoGEALYga0dmx4w4LAFt40ACLFylavQDydEgE9+glvEg1y0LAWmkKVWnUjrmwsiRI0A7gClzoAGbXIliJE72AouOghLx87fwk9AgAxeBIsNDIAOgIE6EgcIPAXGKw6MlE40ETUnHhRAAcaWGhQAG8AFRUyrABfV1gaUVAAchcaGi6AbnSsAA8KqtBEehhXPtAAXlAACmhGrAB+NAamgEo0ADcaeAIFgD5a5qGgA

๐Ÿ’ป Code

// @strict: true
// @declaration: true
// @noCheck: true
// @emitDeclarationOnly: true
// @isolatedDeclarations: true
// @allowJs: false
// @showEmit
// @showEmittedFile: a.d.ts

import {Type} from 'foo';

export const foo = (type?: Type): void => {};
                    ^^^^^^^^^^^ Parameter must have an explicit type annotation with --isolatedDeclarations.(9011)

๐Ÿ™ Actual behavior

Error even though type annotation exists

๐Ÿ™‚ Expected behavior

No error

Additional information about the issue

Sorry, I don't have time at the moment to bisect to the commit that introduced the regression

Andarist commented 2 hours ago

Based on some other recent issues I was looking at - this should report an error about lack of | undefined in the annotation.

MichaelMitchell-at commented 2 hours ago

Based on some other recent issues I was looking at - this should report an error about lack of | undefined in the annotation.

Interesting. Why is that so? Is that only when exactOptionalPropertyTypes is off?

RyanCavanaugh commented 2 hours ago

Seems like a bug?

EOPT doesn't have any effect on parameters FWIW

Andarist commented 2 hours ago

Ah, it might be that the | undefined is required only when dealing with parameter properties (or however those are called). See https://github.com/microsoft/TypeScript/issues/60123 and https://github.com/microsoft/TypeScript/pull/60129

FWIW, this case here is likely also related to an unresolved type that is actually an error type (a special kind of any)