-
Notifications
You must be signed in to change notification settings - Fork 12.9k
fix(39836): unknown
type declaration for catch argument doesn't work in js
#42392
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
Merged
Changes from all commits
Commits
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
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
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
75 changes: 75 additions & 0 deletions
75
tests/baselines/reference/jsdocCatchClauseWithTypeAnnotation.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,75 @@ | ||
tests/cases/conformance/jsdoc/foo.js(20,54): error TS2339: Property 'foo' does not exist on type 'unknown'. | ||
tests/cases/conformance/jsdoc/foo.js(21,54): error TS2339: Property 'foo' does not exist on type 'unknown'. | ||
tests/cases/conformance/jsdoc/foo.js(22,31): error TS1196: Catch clause variable type annotation must be 'any' or 'unknown' if specified. | ||
tests/cases/conformance/jsdoc/foo.js(23,31): error TS1196: Catch clause variable type annotation must be 'any' or 'unknown' if specified. | ||
tests/cases/conformance/jsdoc/foo.js(35,7): error TS2492: Cannot redeclare identifier 'err' in catch clause. | ||
tests/cases/conformance/jsdoc/foo.js(48,31): error TS1196: Catch clause variable type annotation must be 'any' or 'unknown' if specified. | ||
tests/cases/conformance/jsdoc/foo.js(49,31): error TS1196: Catch clause variable type annotation must be 'any' or 'unknown' if specified. | ||
|
||
|
||
==== tests/cases/conformance/jsdoc/foo.js (7 errors) ==== | ||
/** | ||
* @typedef {any} Any | ||
*/ | ||
|
||
/** | ||
* @typedef {unknown} Unknown | ||
*/ | ||
|
||
function fn() { | ||
try { } catch (x) { } // should be OK | ||
try { } catch (/** @type {any} */ err) { } // should be OK | ||
try { } catch (/** @type {Any} */ err) { } // should be OK | ||
try { } catch (/** @type {unknown} */ err) { } // should be OK | ||
try { } catch (/** @type {Unknown} */ err) { } // should be OK | ||
try { } catch (err) { err.foo; } // should be OK | ||
try { } catch (/** @type {any} */ err) { err.foo; } // should be OK | ||
try { } catch (/** @type {Any} */ err) { err.foo; } // should be OK | ||
try { } catch (/** @type {unknown} */ err) { console.log(err); } // should be OK | ||
try { } catch (/** @type {Unknown} */ err) { console.log(err); } // should be OK | ||
try { } catch (/** @type {unknown} */ err) { err.foo; } // error in the body | ||
~~~ | ||
!!! error TS2339: Property 'foo' does not exist on type 'unknown'. | ||
try { } catch (/** @type {Unknown} */ err) { err.foo; } // error in the body | ||
~~~ | ||
!!! error TS2339: Property 'foo' does not exist on type 'unknown'. | ||
try { } catch (/** @type {Error} */ err) { } // error in the type | ||
~~~~~ | ||
!!! error TS1196: Catch clause variable type annotation must be 'any' or 'unknown' if specified. | ||
try { } catch (/** @type {object} */ err) { } // error in the type | ||
~~~~~~ | ||
!!! error TS1196: Catch clause variable type annotation must be 'any' or 'unknown' if specified. | ||
|
||
try { console.log(); } | ||
// @ts-ignore | ||
catch (/** @type {number} */ err) { // e should not be a `number` | ||
console.log(err.toLowerCase()); | ||
} | ||
|
||
// minor bug: shows that the `catch` argument is skipped when checking scope | ||
try { } | ||
catch (err) { | ||
/** @type {string} */ | ||
let err; | ||
~~~ | ||
!!! error TS2492: Cannot redeclare identifier 'err' in catch clause. | ||
} | ||
try { } | ||
catch (err) { | ||
/** @type {boolean} */ | ||
var err; | ||
} | ||
|
||
try { } catch ({ x }) { } // should be OK | ||
try { } catch (/** @type {any} */ { x }) { x.foo; } // should be OK | ||
try { } catch (/** @type {Any} */ { x }) { x.foo;} // should be OK | ||
try { } catch (/** @type {unknown} */ { x }) { console.log(x); } // should be OK | ||
try { } catch (/** @type {Unknown} */ { x }) { console.log(x); } // should be OK | ||
try { } catch (/** @type {Error} */ { x }) { } // error in the type | ||
~~~~~ | ||
!!! error TS1196: Catch clause variable type annotation must be 'any' or 'unknown' if specified. | ||
try { } catch (/** @type {object} */ { x }) { } // error in the type | ||
~~~~~~ | ||
!!! error TS1196: Catch clause variable type annotation must be 'any' or 'unknown' if specified. | ||
} | ||
|
144 changes: 144 additions & 0 deletions
144
tests/baselines/reference/jsdocCatchClauseWithTypeAnnotation.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,144 @@ | ||
//// [foo.js] | ||
/** | ||
* @typedef {any} Any | ||
*/ | ||
|
||
/** | ||
* @typedef {unknown} Unknown | ||
*/ | ||
|
||
function fn() { | ||
try { } catch (x) { } // should be OK | ||
try { } catch (/** @type {any} */ err) { } // should be OK | ||
try { } catch (/** @type {Any} */ err) { } // should be OK | ||
try { } catch (/** @type {unknown} */ err) { } // should be OK | ||
try { } catch (/** @type {Unknown} */ err) { } // should be OK | ||
try { } catch (err) { err.foo; } // should be OK | ||
try { } catch (/** @type {any} */ err) { err.foo; } // should be OK | ||
try { } catch (/** @type {Any} */ err) { err.foo; } // should be OK | ||
try { } catch (/** @type {unknown} */ err) { console.log(err); } // should be OK | ||
try { } catch (/** @type {Unknown} */ err) { console.log(err); } // should be OK | ||
try { } catch (/** @type {unknown} */ err) { err.foo; } // error in the body | ||
try { } catch (/** @type {Unknown} */ err) { err.foo; } // error in the body | ||
try { } catch (/** @type {Error} */ err) { } // error in the type | ||
try { } catch (/** @type {object} */ err) { } // error in the type | ||
|
||
try { console.log(); } | ||
// @ts-ignore | ||
catch (/** @type {number} */ err) { // e should not be a `number` | ||
console.log(err.toLowerCase()); | ||
} | ||
|
||
// minor bug: shows that the `catch` argument is skipped when checking scope | ||
try { } | ||
catch (err) { | ||
/** @type {string} */ | ||
let err; | ||
} | ||
try { } | ||
catch (err) { | ||
/** @type {boolean} */ | ||
var err; | ||
} | ||
|
||
try { } catch ({ x }) { } // should be OK | ||
try { } catch (/** @type {any} */ { x }) { x.foo; } // should be OK | ||
try { } catch (/** @type {Any} */ { x }) { x.foo;} // should be OK | ||
try { } catch (/** @type {unknown} */ { x }) { console.log(x); } // should be OK | ||
try { } catch (/** @type {Unknown} */ { x }) { console.log(x); } // should be OK | ||
try { } catch (/** @type {Error} */ { x }) { } // error in the type | ||
try { } catch (/** @type {object} */ { x }) { } // error in the type | ||
} | ||
|
||
|
||
//// [foo.js] | ||
/** | ||
* @typedef {any} Any | ||
*/ | ||
/** | ||
* @typedef {unknown} Unknown | ||
*/ | ||
function fn() { | ||
try { } | ||
catch (x) { } // should be OK | ||
try { } | ||
catch ( /** @type {any} */err) { } // should be OK | ||
try { } | ||
catch ( /** @type {Any} */err) { } // should be OK | ||
try { } | ||
catch ( /** @type {unknown} */err) { } // should be OK | ||
try { } | ||
catch ( /** @type {Unknown} */err) { } // should be OK | ||
try { } | ||
catch (err) { | ||
err.foo; | ||
} // should be OK | ||
try { } | ||
catch ( /** @type {any} */err) { | ||
err.foo; | ||
} // should be OK | ||
try { } | ||
catch ( /** @type {Any} */err) { | ||
err.foo; | ||
} // should be OK | ||
try { } | ||
catch ( /** @type {unknown} */err) { | ||
console.log(err); | ||
} // should be OK | ||
try { } | ||
catch ( /** @type {Unknown} */err) { | ||
console.log(err); | ||
} // should be OK | ||
try { } | ||
catch ( /** @type {unknown} */err) { | ||
err.foo; | ||
} // error in the body | ||
try { } | ||
catch ( /** @type {Unknown} */err) { | ||
err.foo; | ||
} // error in the body | ||
try { } | ||
catch ( /** @type {Error} */err) { } // error in the type | ||
try { } | ||
catch ( /** @type {object} */err) { } // error in the type | ||
try { | ||
console.log(); | ||
} | ||
// @ts-ignore | ||
catch ( /** @type {number} */err) { // e should not be a `number` | ||
console.log(err.toLowerCase()); | ||
} | ||
// minor bug: shows that the `catch` argument is skipped when checking scope | ||
try { } | ||
catch (err) { | ||
/** @type {string} */ | ||
let err; | ||
} | ||
try { } | ||
catch (err) { | ||
/** @type {boolean} */ | ||
var err; | ||
} | ||
try { } | ||
catch ({ x }) { } // should be OK | ||
try { } | ||
catch ( /** @type {any} */{ x }) { | ||
x.foo; | ||
} // should be OK | ||
try { } | ||
catch ( /** @type {Any} */{ x }) { | ||
x.foo; | ||
} // should be OK | ||
try { } | ||
catch ( /** @type {unknown} */{ x }) { | ||
console.log(x); | ||
} // should be OK | ||
try { } | ||
catch ( /** @type {Unknown} */{ x }) { | ||
console.log(x); | ||
} // should be OK | ||
try { } | ||
catch ( /** @type {Error} */{ x }) { } // error in the type | ||
try { } | ||
catch ( /** @type {object} */{ x }) { } // error in the type | ||
} |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.