Skip to content

Commit be1f892

Browse files
authored
Fix declaration emit of divergent accessors in JS classes (#58172)
1 parent 4b01686 commit be1f892

File tree

5 files changed

+115
-1
lines changed

5 files changed

+115
-1
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9853,7 +9853,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
98539853
/*dotDotDotToken*/ undefined,
98549854
paramSymbol ? parameterToParameterDeclarationName(paramSymbol, getEffectiveParameterDeclaration(paramSymbol), context) : "value",
98559855
/*questionToken*/ undefined,
9856-
isPrivate ? undefined : serializeTypeForDeclaration(context, /*declaration*/ undefined, getTypeOfSymbol(p), p),
9856+
isPrivate ? undefined : serializeTypeForDeclaration(context, /*declaration*/ undefined, getWriteTypeOfSymbol(p), p),
98579857
)],
98589858
/*body*/ undefined,
98599859
),
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//// [tests/cases/compiler/declarationEmitClassAccessorsJs1.ts] ////
2+
3+
//// [index.js]
4+
// https://github.com/microsoft/TypeScript/issues/58167
5+
6+
export class VFile {
7+
/**
8+
* @returns {string}
9+
*/
10+
get path() {
11+
return ''
12+
}
13+
14+
/**
15+
* @param {URL | string} path
16+
*/
17+
set path(path) {
18+
}
19+
}
20+
21+
22+
23+
24+
//// [index.d.ts]
25+
export class VFile {
26+
/**
27+
* @param {URL | string} path
28+
*/
29+
set path(path: string | URL);
30+
/**
31+
* @returns {string}
32+
*/
33+
get path(): string;
34+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//// [tests/cases/compiler/declarationEmitClassAccessorsJs1.ts] ////
2+
3+
=== index.js ===
4+
// https://github.com/microsoft/TypeScript/issues/58167
5+
6+
export class VFile {
7+
>VFile : Symbol(VFile, Decl(index.js, 0, 0))
8+
9+
/**
10+
* @returns {string}
11+
*/
12+
get path() {
13+
>path : Symbol(VFile.path, Decl(index.js, 2, 20), Decl(index.js, 8, 3))
14+
15+
return ''
16+
}
17+
18+
/**
19+
* @param {URL | string} path
20+
*/
21+
set path(path) {
22+
>path : Symbol(VFile.path, Decl(index.js, 2, 20), Decl(index.js, 8, 3))
23+
>path : Symbol(path, Decl(index.js, 13, 11))
24+
}
25+
}
26+
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//// [tests/cases/compiler/declarationEmitClassAccessorsJs1.ts] ////
2+
3+
=== index.js ===
4+
// https://github.com/microsoft/TypeScript/issues/58167
5+
6+
export class VFile {
7+
>VFile : VFile
8+
> : ^^^^^
9+
10+
/**
11+
* @returns {string}
12+
*/
13+
get path() {
14+
>path : string
15+
> : ^^^^^^
16+
17+
return ''
18+
>'' : ""
19+
> : ^^
20+
}
21+
22+
/**
23+
* @param {URL | string} path
24+
*/
25+
set path(path) {
26+
>path : string
27+
> : ^^^^^^
28+
>path : string | URL
29+
> : ^^^^^^^^^^^^
30+
}
31+
}
32+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// @strict: true
2+
// @checkJs: true
3+
// @declaration: true
4+
// @emitDeclarationOnly: true
5+
// @filename: index.js
6+
7+
// https://github.com/microsoft/TypeScript/issues/58167
8+
9+
export class VFile {
10+
/**
11+
* @returns {string}
12+
*/
13+
get path() {
14+
return ''
15+
}
16+
17+
/**
18+
* @param {URL | string} path
19+
*/
20+
set path(path) {
21+
}
22+
}

0 commit comments

Comments
 (0)