Fix declaration emit of divergent accessors in JS classes (#58172)

This commit is contained in:
Mateusz Burzyński 2024-04-16 01:48:04 +02:00 committed by GitHub
parent 4b01686602
commit be1f89271c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 115 additions and 1 deletions

View File

@ -9853,7 +9853,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
/*dotDotDotToken*/ undefined,
paramSymbol ? parameterToParameterDeclarationName(paramSymbol, getEffectiveParameterDeclaration(paramSymbol), context) : "value",
/*questionToken*/ undefined,
isPrivate ? undefined : serializeTypeForDeclaration(context, /*declaration*/ undefined, getTypeOfSymbol(p), p),
isPrivate ? undefined : serializeTypeForDeclaration(context, /*declaration*/ undefined, getWriteTypeOfSymbol(p), p),
)],
/*body*/ undefined,
),

View File

@ -0,0 +1,34 @@
//// [tests/cases/compiler/declarationEmitClassAccessorsJs1.ts] ////
//// [index.js]
// https://github.com/microsoft/TypeScript/issues/58167
export class VFile {
/**
* @returns {string}
*/
get path() {
return ''
}
/**
* @param {URL | string} path
*/
set path(path) {
}
}
//// [index.d.ts]
export class VFile {
/**
* @param {URL | string} path
*/
set path(path: string | URL);
/**
* @returns {string}
*/
get path(): string;
}

View File

@ -0,0 +1,26 @@
//// [tests/cases/compiler/declarationEmitClassAccessorsJs1.ts] ////
=== index.js ===
// https://github.com/microsoft/TypeScript/issues/58167
export class VFile {
>VFile : Symbol(VFile, Decl(index.js, 0, 0))
/**
* @returns {string}
*/
get path() {
>path : Symbol(VFile.path, Decl(index.js, 2, 20), Decl(index.js, 8, 3))
return ''
}
/**
* @param {URL | string} path
*/
set path(path) {
>path : Symbol(VFile.path, Decl(index.js, 2, 20), Decl(index.js, 8, 3))
>path : Symbol(path, Decl(index.js, 13, 11))
}
}

View File

@ -0,0 +1,32 @@
//// [tests/cases/compiler/declarationEmitClassAccessorsJs1.ts] ////
=== index.js ===
// https://github.com/microsoft/TypeScript/issues/58167
export class VFile {
>VFile : VFile
> : ^^^^^
/**
* @returns {string}
*/
get path() {
>path : string
> : ^^^^^^
return ''
>'' : ""
> : ^^
}
/**
* @param {URL | string} path
*/
set path(path) {
>path : string
> : ^^^^^^
>path : string | URL
> : ^^^^^^^^^^^^
}
}

View File

@ -0,0 +1,22 @@
// @strict: true
// @checkJs: true
// @declaration: true
// @emitDeclarationOnly: true
// @filename: index.js
// https://github.com/microsoft/TypeScript/issues/58167
export class VFile {
/**
* @returns {string}
*/
get path() {
return ''
}
/**
* @param {URL | string} path
*/
set path(path) {
}
}