-
Notifications
You must be signed in to change notification settings - Fork 12.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(39836): allow type declaration/unknown type in catch arguments in…
… JavaScript files
- Loading branch information
1 parent
b5bab16
commit 43c907c
Showing
12 changed files
with
585 additions
and
14 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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.