-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Assume that type node annotations resolving to error types can be reused #60195
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
Merged
jakebailey
merged 4 commits into
microsoft:main
from
Andarist:fix/confusing-cascading-id-error
Oct 11, 2024
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
tests/baselines/reference/isolatedDeclarationErrorTypes1.errors.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
isolatedDeclarationErrorTypes1.ts(3,28): error TS2307: Cannot find module 'foo' or its corresponding type declarations. | ||
|
||
|
||
==== isolatedDeclarationErrorTypes1.ts (1 errors) ==== | ||
// https://github.com/microsoft/TypeScript/issues/60192 | ||
|
||
import { Unresolved } from "foo"; | ||
~~~~~ | ||
!!! error TS2307: Cannot find module 'foo' or its corresponding type declarations. | ||
|
||
export const foo1 = (type?: Unresolved): void => {}; | ||
export const foo2 = (type?: Unresolved | undefined): void => {}; | ||
export const foo3 = (type: Unresolved): void => {}; | ||
|
30 changes: 30 additions & 0 deletions
30
tests/baselines/reference/isolatedDeclarationErrorTypes1.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
//// [tests/cases/compiler/isolatedDeclarationErrorTypes1.ts] //// | ||
|
||
//// [isolatedDeclarationErrorTypes1.ts] | ||
// https://github.com/microsoft/TypeScript/issues/60192 | ||
|
||
import { Unresolved } from "foo"; | ||
|
||
export const foo1 = (type?: Unresolved): void => {}; | ||
export const foo2 = (type?: Unresolved | undefined): void => {}; | ||
export const foo3 = (type: Unresolved): void => {}; | ||
|
||
|
||
//// [isolatedDeclarationErrorTypes1.js] | ||
"use strict"; | ||
// https://github.com/microsoft/TypeScript/issues/60192 | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.foo3 = exports.foo2 = exports.foo1 = void 0; | ||
const foo1 = (type) => { }; | ||
exports.foo1 = foo1; | ||
const foo2 = (type) => { }; | ||
exports.foo2 = foo2; | ||
const foo3 = (type) => { }; | ||
exports.foo3 = foo3; | ||
|
||
|
||
//// [isolatedDeclarationErrorTypes1.d.ts] | ||
import { Unresolved } from "foo"; | ||
export declare const foo1: (type?: Unresolved) => void; | ||
export declare const foo2: (type?: Unresolved | undefined) => void; | ||
export declare const foo3: (type: Unresolved) => void; |
23 changes: 23 additions & 0 deletions
23
tests/baselines/reference/isolatedDeclarationErrorTypes1.symbols
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
//// [tests/cases/compiler/isolatedDeclarationErrorTypes1.ts] //// | ||
|
||
=== isolatedDeclarationErrorTypes1.ts === | ||
// https://github.com/microsoft/TypeScript/issues/60192 | ||
|
||
import { Unresolved } from "foo"; | ||
>Unresolved : Symbol(Unresolved, Decl(isolatedDeclarationErrorTypes1.ts, 2, 8)) | ||
|
||
export const foo1 = (type?: Unresolved): void => {}; | ||
>foo1 : Symbol(foo1, Decl(isolatedDeclarationErrorTypes1.ts, 4, 12)) | ||
>type : Symbol(type, Decl(isolatedDeclarationErrorTypes1.ts, 4, 21)) | ||
>Unresolved : Symbol(Unresolved, Decl(isolatedDeclarationErrorTypes1.ts, 2, 8)) | ||
|
||
export const foo2 = (type?: Unresolved | undefined): void => {}; | ||
>foo2 : Symbol(foo2, Decl(isolatedDeclarationErrorTypes1.ts, 5, 12)) | ||
>type : Symbol(type, Decl(isolatedDeclarationErrorTypes1.ts, 5, 21)) | ||
>Unresolved : Symbol(Unresolved, Decl(isolatedDeclarationErrorTypes1.ts, 2, 8)) | ||
|
||
export const foo3 = (type: Unresolved): void => {}; | ||
>foo3 : Symbol(foo3, Decl(isolatedDeclarationErrorTypes1.ts, 6, 12)) | ||
>type : Symbol(type, Decl(isolatedDeclarationErrorTypes1.ts, 6, 21)) | ||
>Unresolved : Symbol(Unresolved, Decl(isolatedDeclarationErrorTypes1.ts, 2, 8)) | ||
|
33 changes: 33 additions & 0 deletions
33
tests/baselines/reference/isolatedDeclarationErrorTypes1.types
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
//// [tests/cases/compiler/isolatedDeclarationErrorTypes1.ts] //// | ||
|
||
=== isolatedDeclarationErrorTypes1.ts === | ||
// https://github.com/microsoft/TypeScript/issues/60192 | ||
|
||
import { Unresolved } from "foo"; | ||
>Unresolved : any | ||
> : ^^^ | ||
|
||
export const foo1 = (type?: Unresolved): void => {}; | ||
>foo1 : (type?: Unresolved) => void | ||
> : ^ ^^^ ^^^^^ | ||
>(type?: Unresolved): void => {} : (type?: Unresolved) => void | ||
> : ^ ^^^ ^^^^^ | ||
>type : any | ||
> : ^^^ | ||
|
||
export const foo2 = (type?: Unresolved | undefined): void => {}; | ||
>foo2 : (type?: Unresolved | undefined) => void | ||
> : ^ ^^^ ^^^^^ | ||
>(type?: Unresolved | undefined): void => {} : (type?: Unresolved | undefined) => void | ||
> : ^ ^^^ ^^^^^ | ||
>type : any | ||
> : ^^^ | ||
|
||
export const foo3 = (type: Unresolved): void => {}; | ||
>foo3 : (type: Unresolved) => void | ||
> : ^ ^^ ^^^^^ | ||
>(type: Unresolved): void => {} : (type: Unresolved) => void | ||
> : ^ ^^ ^^^^^ | ||
>type : Unresolved | ||
> : ^^^^^^^^^^ | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// @isolatedDeclarations: true | ||
// @strict: true | ||
// @declaration: true | ||
// @moduleResolution: nodenext | ||
// @module: nodenext | ||
|
||
// https://github.com/microsoft/TypeScript/issues/60192 | ||
|
||
import { Unresolved } from "foo"; | ||
|
||
export const foo1 = (type?: Unresolved): void => {}; | ||
export const foo2 = (type?: Unresolved | undefined): void => {}; | ||
export const foo3 = (type: Unresolved): void => {}; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be handled elsewhere but this place is an easy and effective fix.
Note that in a sense this was already happening - just in different situations. Consider this:
In here both the
annotationType
andtype
are error types, they just happen to be the same aliased error types. So they are assumed to be the same on the basis oftypeFromTypeNode === type
intypeNodeIsEquivalentToType
.The reported case is the same yet different. Both types are also error types there but the
type
is a regular non-aliased error type whereas theannotationType
is an aliased error type. Based on thattypeNodeIsEquivalentToType
doesn't assume that they are the same and thustypeFromParameter
goes intoinferTypeOfDeclaration
which leads to reporting the error.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a condition in which this will cause us to try and print something unprintable?
Or will it not matter because it'll be an error anyway?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I propose this fix mainly on the assumption of "will it not matter because it'll be an error anyway". It seems to me that if the error is there anyway then any emit is basically a fair game. It should reuse the annotation node - so at the very least it should just be broken in the same way.