-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Improved 'nameless' JSDoc typedef support. #28162
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,6 @@ | |
* }} | ||
*/ | ||
export const foo = 5; | ||
>foo : 5 | ||
>foo : error | ||
>5 : 5 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
=== tests/cases/compiler/export.js === | ||
export type foo = 5; | ||
>foo : Symbol(foo, Decl(export.js, 0, 0), Decl(export.js, 5, 12)) | ||
>foo : Symbol(foo, Decl(export.js, 0, 0), Decl(export.js, 2, 3)) | ||
|
||
/** | ||
* @typedef {{ | ||
* }} | ||
*/ | ||
export const foo = 5; | ||
>foo : Symbol(foo, Decl(export.js, 0, 0), Decl(export.js, 5, 12)) | ||
>foo : Symbol(foo, Decl(export.js, 5, 12)) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,6 @@ export type foo = 5; | |
* }} | ||
*/ | ||
export const foo = 5; | ||
>foo : 5 | ||
>foo : any | ||
>5 : 5 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
tests/cases/conformance/jsdoc/a.js(11,1): error TS2693: 'nameless' only refers to a type, but is being used as a value here. | ||
tests/cases/conformance/jsdoc/a.js(26,5): error TS2693: 'notOK' only refers to a type, but is being used as a value here. | ||
tests/cases/conformance/jsdoc/a.js(32,7): error TS1155: 'const' declarations must be initialized. | ||
|
||
|
||
==== tests/cases/conformance/jsdoc/a.js (3 errors) ==== | ||
/** | ||
* @typedef {number} | ||
*/ | ||
var nameless; | ||
|
||
/** | ||
* @typedef {number} named | ||
*/ | ||
var this_is_not_the_name = true; | ||
|
||
nameless = 123; // nameless is not a value | ||
~~~~~~~~ | ||
!!! error TS2693: 'nameless' only refers to a type, but is being used as a value here. | ||
|
||
/** | ||
* @param {named} p1 | ||
* @param {nameless} p2 | ||
*/ | ||
function abc(p1, p2) {} | ||
|
||
/** | ||
* @param {named} p1 | ||
* @param {nameless} p2 | ||
*/ | ||
export function breakThings(p1, p2) {} | ||
|
||
/** @typedef {number} */ | ||
var notOK = 1; | ||
~~~~~ | ||
!!! error TS2693: 'notOK' only refers to a type, but is being used as a value here. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here |
||
|
||
/** @typedef {string} */ | ||
let thisIsOK; | ||
|
||
/** @typedef {{L: number}} */ | ||
const notLegalButShouldBe; | ||
~~~~~~~~~~~~~~~~~~~ | ||
!!! error TS1155: 'const' declarations must be initialized. | ||
|
||
==== tests/cases/conformance/jsdoc/b.js (0 errors) ==== | ||
/** | ||
* @typedef {{ | ||
* p: string | ||
* }} | ||
*/ | ||
export var type1; | ||
|
||
==== tests/cases/conformance/jsdoc/c.js (0 errors) ==== | ||
import { type1 as aliased } from './b'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the other change of this PR, I think. I'm not sure I like this one either -- it encourages checkJS users to import and export real variables at runtime just for the purposes of creating aliases at compile time. There's no general guarantee that these imports and exports will get optimised away. |
||
|
||
/** | ||
* @param {aliased} pt1 | ||
*/ | ||
function f1(pt1) {} | ||
|
||
/** @type {{ p2?: any }} */ | ||
var k = {}; | ||
|
||
/** | ||
* @typedef {aliased} | ||
*/ | ||
k.p2; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
=== tests/cases/conformance/jsdoc/a.js === | ||
/** | ||
* @typedef {number} | ||
*/ | ||
var nameless; | ||
>nameless : Symbol(nameless, Decl(a.js, 3, 3), Decl(a.js, 1, 3)) | ||
|
||
/** | ||
* @typedef {number} named | ||
*/ | ||
var this_is_not_the_name = true; | ||
>this_is_not_the_name : Symbol(this_is_not_the_name, Decl(a.js, 8, 3)) | ||
|
||
nameless = 123; // nameless is not a value | ||
|
||
/** | ||
* @param {named} p1 | ||
* @param {nameless} p2 | ||
*/ | ||
function abc(p1, p2) {} | ||
>abc : Symbol(abc, Decl(a.js, 10, 15)) | ||
>p1 : Symbol(p1, Decl(a.js, 16, 13)) | ||
>p2 : Symbol(p2, Decl(a.js, 16, 16)) | ||
|
||
/** | ||
* @param {named} p1 | ||
* @param {nameless} p2 | ||
*/ | ||
export function breakThings(p1, p2) {} | ||
>breakThings : Symbol(breakThings, Decl(a.js, 16, 23)) | ||
>p1 : Symbol(p1, Decl(a.js, 22, 28)) | ||
>p2 : Symbol(p2, Decl(a.js, 22, 31)) | ||
|
||
/** @typedef {number} */ | ||
var notOK = 1; | ||
>notOK : Symbol(notOK, Decl(a.js, 25, 3), Decl(a.js, 24, 4)) | ||
|
||
/** @typedef {string} */ | ||
let thisIsOK; | ||
>thisIsOK : Symbol(thisIsOK, Decl(a.js, 28, 3), Decl(a.js, 27, 4)) | ||
|
||
/** @typedef {{L: number}} */ | ||
const notLegalButShouldBe; | ||
>notLegalButShouldBe : Symbol(notLegalButShouldBe, Decl(a.js, 31, 5), Decl(a.js, 30, 4)) | ||
|
||
=== tests/cases/conformance/jsdoc/b.js === | ||
/** | ||
* @typedef {{ | ||
* p: string | ||
* }} | ||
*/ | ||
export var type1; | ||
>type1 : Symbol(type1, Decl(b.js, 5, 10), Decl(b.js, 1, 3)) | ||
|
||
=== tests/cases/conformance/jsdoc/c.js === | ||
import { type1 as aliased } from './b'; | ||
>type1 : Symbol(aliased, Decl(c.js, 0, 8)) | ||
>aliased : Symbol(aliased, Decl(c.js, 0, 8)) | ||
|
||
/** | ||
* @param {aliased} pt1 | ||
*/ | ||
function f1(pt1) {} | ||
>f1 : Symbol(f1, Decl(c.js, 0, 39)) | ||
>pt1 : Symbol(pt1, Decl(c.js, 5, 12)) | ||
|
||
/** @type {{ p2?: any }} */ | ||
var k = {}; | ||
>k : Symbol(k, Decl(c.js, 8, 3)) | ||
|
||
/** | ||
* @typedef {aliased} | ||
*/ | ||
k.p2; | ||
>k.p2 : Symbol(p2, Decl(c.js, 7, 12)) | ||
>k : Symbol(k, Decl(c.js, 8, 3)) | ||
>p2 : Symbol(p2, Decl(c.js, 7, 12)) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
=== tests/cases/conformance/jsdoc/a.js === | ||
/** | ||
* @typedef {number} | ||
*/ | ||
var nameless; | ||
>nameless : any | ||
|
||
/** | ||
* @typedef {number} named | ||
*/ | ||
var this_is_not_the_name = true; | ||
>this_is_not_the_name : boolean | ||
>true : true | ||
|
||
nameless = 123; // nameless is not a value | ||
>nameless = 123 : 123 | ||
>nameless : any | ||
>123 : 123 | ||
|
||
/** | ||
* @param {named} p1 | ||
* @param {nameless} p2 | ||
*/ | ||
function abc(p1, p2) {} | ||
>abc : (p1: number, p2: number) => void | ||
>p1 : number | ||
>p2 : number | ||
|
||
/** | ||
* @param {named} p1 | ||
* @param {nameless} p2 | ||
*/ | ||
export function breakThings(p1, p2) {} | ||
>breakThings : (p1: number, p2: number) => void | ||
>p1 : number | ||
>p2 : number | ||
|
||
/** @typedef {number} */ | ||
var notOK = 1; | ||
>notOK : any | ||
>1 : 1 | ||
|
||
/** @typedef {string} */ | ||
let thisIsOK; | ||
>thisIsOK : any | ||
|
||
/** @typedef {{L: number}} */ | ||
const notLegalButShouldBe; | ||
>notLegalButShouldBe : any | ||
|
||
=== tests/cases/conformance/jsdoc/b.js === | ||
/** | ||
* @typedef {{ | ||
* p: string | ||
* }} | ||
*/ | ||
export var type1; | ||
>type1 : any | ||
|
||
=== tests/cases/conformance/jsdoc/c.js === | ||
import { type1 as aliased } from './b'; | ||
>type1 : any | ||
>aliased : any | ||
|
||
/** | ||
* @param {aliased} pt1 | ||
*/ | ||
function f1(pt1) {} | ||
>f1 : (pt1: { p: string; }) => void | ||
>pt1 : { p: string; } | ||
|
||
/** @type {{ p2?: any }} */ | ||
var k = {}; | ||
>k : { p2?: any; } | ||
>{} : {} | ||
|
||
/** | ||
* @typedef {aliased} | ||
*/ | ||
k.p2; | ||
>k.p2 : any | ||
>k : { p2?: any; } | ||
>p2 : any | ||
|
||
|
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 don't like this error. We can't change the semantics of JS or TS such that
nameless
no longer has a value meaning.