diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 2515d81a58f7e..72bc6933c2ad0 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -9438,7 +9438,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { else { const statement = factory.createVariableStatement(/*modifiers*/ undefined, factory.createVariableDeclarationList([ factory.createVariableDeclaration(varName, /*exclamationToken*/ undefined, serializeTypeForDeclaration(context, typeToSerialize, symbol, enclosingDeclaration, includePrivateSymbol, bundled)) - ], NodeFlags.Const)); + ], context.enclosingDeclaration?.kind === SyntaxKind.ModuleDeclaration ? NodeFlags.Let : NodeFlags.Const)); // Inlined JSON types exported with [module.]exports= will already emit an export=, so should use `declare`. // Otherwise, the type itself should be exported. addResult(statement, diff --git a/tests/baselines/reference/argumentsReferenceInConstructor5_Js.js b/tests/baselines/reference/argumentsReferenceInConstructor5_Js.js index 84f6472d31853..148a15c2978e6 100644 --- a/tests/baselines/reference/argumentsReferenceInConstructor5_Js.js +++ b/tests/baselines/reference/argumentsReferenceInConstructor5_Js.js @@ -27,7 +27,7 @@ class A { //// [a.d.ts] declare namespace bar { - const arguments: {}; + let arguments: {}; } declare class A { /** diff --git a/tests/baselines/reference/argumentsReferenceInMethod5_Js.js b/tests/baselines/reference/argumentsReferenceInMethod5_Js.js index 076bdd2f4d733..65ce6a129ecb7 100644 --- a/tests/baselines/reference/argumentsReferenceInMethod5_Js.js +++ b/tests/baselines/reference/argumentsReferenceInMethod5_Js.js @@ -25,7 +25,7 @@ class A { //// [a.d.ts] declare namespace bar { - const arguments: {}; + let arguments: {}; } declare class A { /** diff --git a/tests/baselines/reference/expandoOnAlias.js b/tests/baselines/reference/expandoOnAlias.js index 39e20fb38d70a..dc7ed2ad38522 100644 --- a/tests/baselines/reference/expandoOnAlias.js +++ b/tests/baselines/reference/expandoOnAlias.js @@ -27,7 +27,7 @@ config.y; export class Vue { } export namespace config { - const x: number; + let x: number; } //// [test.d.ts] export {}; diff --git a/tests/baselines/reference/jsDeclarationsClassExtendsVisibility.js b/tests/baselines/reference/jsDeclarationsClassExtendsVisibility.js index 1a5b659985618..bbe7783650f78 100644 --- a/tests/baselines/reference/jsDeclarationsClassExtendsVisibility.js +++ b/tests/baselines/reference/jsDeclarationsClassExtendsVisibility.js @@ -65,6 +65,6 @@ declare namespace Foo { } import Bar = require("./bar"); declare namespace Strings { - const a: string; - const b: string; + let a: string; + let b: string; } diff --git a/tests/baselines/reference/jsDeclarationsClassStatic.js b/tests/baselines/reference/jsDeclarationsClassStatic.js index dcb8938ff6e97..0b2ad2451ba9b 100644 --- a/tests/baselines/reference/jsDeclarationsClassStatic.js +++ b/tests/baselines/reference/jsDeclarationsClassStatic.js @@ -63,8 +63,8 @@ declare namespace Handler { } declare function statische(): void; declare namespace Strings { - const a: string; - const b: string; + let a: string; + let b: string; } type HandlerOptions = { /** diff --git a/tests/baselines/reference/jsDeclarationsClassStatic2.js b/tests/baselines/reference/jsDeclarationsClassStatic2.js new file mode 100644 index 0000000000000..103041325327d --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsClassStatic2.js @@ -0,0 +1,30 @@ +//// [tests/cases/conformance/jsdoc/declarations/jsDeclarationsClassStatic2.ts] //// + +//// [Foo.js] +class Base { + static foo = ""; +} +export class Foo extends Base {} +Foo.foo = "foo"; + +//// [Bar.ts] +import { Foo } from "./Foo.js"; + +class Bar extends Foo {} +Bar.foo = "foo"; + + + + +//// [Foo.d.ts] +export class Foo extends Base { +} +export namespace Foo { + let foo: string; +} +declare class Base { + static foo: string; +} +export {}; +//// [Bar.d.ts] +export {}; diff --git a/tests/baselines/reference/jsDeclarationsClassStatic2.symbols b/tests/baselines/reference/jsDeclarationsClassStatic2.symbols new file mode 100644 index 0000000000000..22c05ef9d75a3 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsClassStatic2.symbols @@ -0,0 +1,29 @@ +=== tests/cases/conformance/jsdoc/declarations/Foo.js === +class Base { +>Base : Symbol(Base, Decl(Foo.js, 0, 0)) + + static foo = ""; +>foo : Symbol(Base.foo, Decl(Foo.js, 0, 12)) +} +export class Foo extends Base {} +>Foo : Symbol(Foo, Decl(Foo.js, 2, 1), Decl(Foo.js, 3, 32)) +>Base : Symbol(Base, Decl(Foo.js, 0, 0)) + +Foo.foo = "foo"; +>Foo.foo : Symbol(Foo.foo, Decl(Foo.js, 3, 32)) +>Foo : Symbol(Foo, Decl(Foo.js, 2, 1), Decl(Foo.js, 3, 32)) +>foo : Symbol(Foo.foo, Decl(Foo.js, 3, 32)) + +=== tests/cases/conformance/jsdoc/declarations/Bar.ts === +import { Foo } from "./Foo.js"; +>Foo : Symbol(Foo, Decl(Bar.ts, 0, 8)) + +class Bar extends Foo {} +>Bar : Symbol(Bar, Decl(Bar.ts, 0, 31)) +>Foo : Symbol(Foo, Decl(Bar.ts, 0, 8)) + +Bar.foo = "foo"; +>Bar.foo : Symbol(Foo.foo, Decl(Foo.js, 3, 32)) +>Bar : Symbol(Bar, Decl(Bar.ts, 0, 31)) +>foo : Symbol(Foo.foo, Decl(Foo.js, 3, 32)) + diff --git a/tests/baselines/reference/jsDeclarationsClassStatic2.types b/tests/baselines/reference/jsDeclarationsClassStatic2.types new file mode 100644 index 0000000000000..819ef7d71458a --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsClassStatic2.types @@ -0,0 +1,34 @@ +=== tests/cases/conformance/jsdoc/declarations/Foo.js === +class Base { +>Base : Base + + static foo = ""; +>foo : string +>"" : "" +} +export class Foo extends Base {} +>Foo : Foo +>Base : Base + +Foo.foo = "foo"; +>Foo.foo = "foo" : "foo" +>Foo.foo : string +>Foo : typeof Foo +>foo : string +>"foo" : "foo" + +=== tests/cases/conformance/jsdoc/declarations/Bar.ts === +import { Foo } from "./Foo.js"; +>Foo : typeof Foo + +class Bar extends Foo {} +>Bar : Bar +>Foo : Foo + +Bar.foo = "foo"; +>Bar.foo = "foo" : "foo" +>Bar.foo : string +>Bar : typeof Bar +>foo : string +>"foo" : "foo" + diff --git a/tests/baselines/reference/jsDeclarationsClassStaticMethodAugmentation.js b/tests/baselines/reference/jsDeclarationsClassStaticMethodAugmentation.js index 2640672f16485..141c367d32b90 100644 --- a/tests/baselines/reference/jsDeclarationsClassStaticMethodAugmentation.js +++ b/tests/baselines/reference/jsDeclarationsClassStaticMethodAugmentation.js @@ -25,6 +25,6 @@ export class Clazz { export namespace Clazz { function method(): void; namespace method { - const prop: number; + let prop: number; } } diff --git a/tests/baselines/reference/jsDeclarationsConstsAsNamespacesWithReferences.js b/tests/baselines/reference/jsDeclarationsConstsAsNamespacesWithReferences.js index 3ac594f0a8849..d979be24e13b7 100644 --- a/tests/baselines/reference/jsDeclarationsConstsAsNamespacesWithReferences.js +++ b/tests/baselines/reference/jsDeclarationsConstsAsNamespacesWithReferences.js @@ -18,7 +18,7 @@ export const brandColors = { //// [index.d.ts] export namespace colors { - const royalBlue: string; + let royalBlue: string; } export namespace brandColors { import purple = colors.royalBlue; diff --git a/tests/baselines/reference/jsDeclarationsEnumTag.js b/tests/baselines/reference/jsDeclarationsEnumTag.js index 7dedb929011aa..8c3c1f2a1b108 100644 --- a/tests/baselines/reference/jsDeclarationsEnumTag.js +++ b/tests/baselines/reference/jsDeclarationsEnumTag.js @@ -113,15 +113,15 @@ export function consume(t: Target, s: Second, f: Fs): void; export function ff(s: string): any; export type Target = string; export namespace Target { - const START: string; - const MIDDLE: string; - const END: string; - const OK_I_GUESS: number; + let START: string; + let MIDDLE: string; + let END: string; + let OK_I_GUESS: number; } export type Second = number; export namespace Second { - const OK: number; - const FINE: number; + let OK: number; + let FINE: number; } export type Fs = (arg0: number) => number; export namespace Fs { diff --git a/tests/baselines/reference/jsDeclarationsExportAssignedClassInstance3.js b/tests/baselines/reference/jsDeclarationsExportAssignedClassInstance3.js index 204b2b480509c..afcfe8df53294 100644 --- a/tests/baselines/reference/jsDeclarationsExportAssignedClassInstance3.js +++ b/tests/baselines/reference/jsDeclarationsExportAssignedClassInstance3.js @@ -21,5 +21,5 @@ module.exports.additional = 20; //// [index.d.ts] -export const member: number; -export const additional: 20; +export let member: number; +export let additional: 20; diff --git a/tests/baselines/reference/jsDeclarationsExportAssignmentExpressionPlusSecondary.js b/tests/baselines/reference/jsDeclarationsExportAssignmentExpressionPlusSecondary.js index b0ea33b822197..ef530fd6fb5f3 100644 --- a/tests/baselines/reference/jsDeclarationsExportAssignmentExpressionPlusSecondary.js +++ b/tests/baselines/reference/jsDeclarationsExportAssignmentExpressionPlusSecondary.js @@ -30,11 +30,11 @@ module.exports.Strings = Strings; //// [index.d.ts] export namespace Strings { - const a: string; - const b: string; + let a: string; + let b: string; } -export declare const thing: string; -export declare const also: string; +export declare let thing: string; +export declare let also: string; export declare namespace desc { - const item: string; + let item: string; } diff --git a/tests/baselines/reference/jsDeclarationsExportAssignmentWithKeywordName.js b/tests/baselines/reference/jsDeclarationsExportAssignmentWithKeywordName.js index ced36f2f1738d..9a8eeb663533c 100644 --- a/tests/baselines/reference/jsDeclarationsExportAssignmentWithKeywordName.js +++ b/tests/baselines/reference/jsDeclarationsExportAssignmentWithKeywordName.js @@ -21,8 +21,8 @@ module.exports = { //// [index.d.ts] export var x: number; -declare const _extends: string; +declare let _extends: string; export declare namespace more { - const others: string[]; + let others: string[]; } export { _extends as extends }; diff --git a/tests/baselines/reference/jsDeclarationsExportDefinePropertyEmit.js b/tests/baselines/reference/jsDeclarationsExportDefinePropertyEmit.js index d7c256a545eed..e16fd620f4387 100644 --- a/tests/baselines/reference/jsDeclarationsExportDefinePropertyEmit.js +++ b/tests/baselines/reference/jsDeclarationsExportDefinePropertyEmit.js @@ -114,7 +114,7 @@ Object.defineProperty(module.exports, "j", { value: function j() { } }); export function a(): void; export function b(): void; export namespace b { - const cat: string; + let cat: string; } /** * @param {number} a diff --git a/tests/baselines/reference/jsDeclarationsExportSubAssignments.js b/tests/baselines/reference/jsDeclarationsExportSubAssignments.js index 88f9555a0794c..9000492844e31 100644 --- a/tests/baselines/reference/jsDeclarationsExportSubAssignments.js +++ b/tests/baselines/reference/jsDeclarationsExportSubAssignments.js @@ -29,6 +29,6 @@ declare namespace Foo { export { Strings }; } declare namespace Strings { - const a: string; - const b: string; + let a: string; + let b: string; } diff --git a/tests/baselines/reference/jsDeclarationsFunctionKeywordProp.js b/tests/baselines/reference/jsDeclarationsFunctionKeywordProp.js index 104a853f2af85..5396c9c631cdf 100644 --- a/tests/baselines/reference/jsDeclarationsFunctionKeywordProp.js +++ b/tests/baselines/reference/jsDeclarationsFunctionKeywordProp.js @@ -24,18 +24,18 @@ baz.normal = false; //// [source.d.ts] declare function foo(): void; declare namespace foo { - const _null: boolean; + let _null: boolean; export { _null as null }; } declare function bar(): void; declare namespace bar { - const async: boolean; - const normal: boolean; + let async: boolean; + let normal: boolean; } declare function baz(): void; declare namespace baz { - const _class: boolean; + let _class: boolean; export { _class as class }; - const normal_1: boolean; + let normal_1: boolean; export { normal_1 as normal }; } diff --git a/tests/baselines/reference/jsDeclarationsFunctionKeywordPropExhaustive.js b/tests/baselines/reference/jsDeclarationsFunctionKeywordPropExhaustive.js index a79090418d30f..0e8af0342a1a4 100644 --- a/tests/baselines/reference/jsDeclarationsFunctionKeywordPropExhaustive.js +++ b/tests/baselines/reference/jsDeclarationsFunctionKeywordPropExhaustive.js @@ -169,127 +169,127 @@ foo.of = 1; //// [source.d.ts] declare function foo(): void; declare namespace foo { - export const x: number; - export const y: number; - const _break: number; + export let x: number; + export let y: number; + let _break: number; export { _break as break }; - const _case: number; + let _case: number; export { _case as case }; - const _catch: number; + let _catch: number; export { _catch as catch }; - const _class: number; + let _class: number; export { _class as class }; - const _const: number; + let _const: number; export { _const as const }; - const _continue: number; + let _continue: number; export { _continue as continue }; - const _debugger: number; + let _debugger: number; export { _debugger as debugger }; - const _default: number; + let _default: number; export { _default as default }; - const _delete: number; + let _delete: number; export { _delete as delete }; - const _do: number; + let _do: number; export { _do as do }; - const _else: number; + let _else: number; export { _else as else }; - const _enum: number; + let _enum: number; export { _enum as enum }; - const _export: number; + let _export: number; export { _export as export }; - const _extends: number; + let _extends: number; export { _extends as extends }; - const _false: number; + let _false: number; export { _false as false }; - const _finally: number; + let _finally: number; export { _finally as finally }; - const _for: number; + let _for: number; export { _for as for }; - const _function: number; + let _function: number; export { _function as function }; - const _if: number; + let _if: number; export { _if as if }; - const _import: number; + let _import: number; export { _import as import }; - const _in: number; + let _in: number; export { _in as in }; - const _instanceof: number; + let _instanceof: number; export { _instanceof as instanceof }; - const _new: number; + let _new: number; export { _new as new }; - const _null: number; + let _null: number; export { _null as null }; - const _return: number; + let _return: number; export { _return as return }; - const _super: number; + let _super: number; export { _super as super }; - const _switch: number; + let _switch: number; export { _switch as switch }; - const _this: number; + let _this: number; export { _this as this }; - const _throw: number; + let _throw: number; export { _throw as throw }; - const _true: number; + let _true: number; export { _true as true }; - const _try: number; + let _try: number; export { _try as try }; - const _typeof: number; + let _typeof: number; export { _typeof as typeof }; - const _var: number; + let _var: number; export { _var as var }; - const _void: number; + let _void: number; export { _void as void }; - const _while: number; + let _while: number; export { _while as while }; - const _with: number; + let _with: number; export { _with as with }; - const _implements: number; + let _implements: number; export { _implements as implements }; - const _interface: number; + let _interface: number; export { _interface as interface }; - const _let: number; + let _let: number; export { _let as let }; - const _package: number; + let _package: number; export { _package as package }; - const _private: number; + let _private: number; export { _private as private }; - const _protected: number; + let _protected: number; export { _protected as protected }; - const _public: number; + let _public: number; export { _public as public }; - const _static: number; + let _static: number; export { _static as static }; - const _yield: number; + let _yield: number; export { _yield as yield }; - export const abstract: number; - export const as: number; - export const asserts: number; - export const any: number; - export const async: number; - export const await: number; - export const boolean: number; - export const constructor: number; - export const declare: number; - export const get: number; - export const infer: number; - export const is: number; - export const keyof: number; - export const module: number; - export const namespace: number; - export const never: number; - export const readonly: number; - export const require: number; - export const number: number; - export const object: number; - export const set: number; - export const string: number; - export const symbol: number; - export const type: number; - export const undefined: number; - export const unique: number; - export const unknown: number; - export const from: number; - export const global: number; - export const bigint: number; - export const of: number; + export let abstract: number; + export let as: number; + export let asserts: number; + export let any: number; + export let async: number; + export let await: number; + export let boolean: number; + export let constructor: number; + export let declare: number; + export let get: number; + export let infer: number; + export let is: number; + export let keyof: number; + export let module: number; + export let namespace: number; + export let never: number; + export let readonly: number; + export let require: number; + export let number: number; + export let object: number; + export let set: number; + export let string: number; + export let symbol: number; + export let type: number; + export let undefined: number; + export let unique: number; + export let unknown: number; + export let from: number; + export let global: number; + export let bigint: number; + export let of: number; } diff --git a/tests/baselines/reference/jsDeclarationsFunctions.js b/tests/baselines/reference/jsDeclarationsFunctions.js index 271a8e9deea84..594af849a6379 100644 --- a/tests/baselines/reference/jsDeclarationsFunctions.js +++ b/tests/baselines/reference/jsDeclarationsFunctions.js @@ -126,7 +126,7 @@ exports.jj = j; export function a(): void; export function b(): void; export namespace b { - const cat: string; + let cat: string; } export function c(): void; export namespace c { diff --git a/tests/baselines/reference/jsDeclarationsFunctionsCjs.js b/tests/baselines/reference/jsDeclarationsFunctionsCjs.js index e933efe112cb3..c893cc846a931 100644 --- a/tests/baselines/reference/jsDeclarationsFunctionsCjs.js +++ b/tests/baselines/reference/jsDeclarationsFunctionsCjs.js @@ -117,7 +117,7 @@ module.exports.j = function j() { }; export function a(): void; export function b(): void; export namespace b { - const cat: string; + let cat: string; } export function c(): void; export namespace c { diff --git a/tests/baselines/reference/jsDeclarationsImportAliasExposedWithinNamespace.js b/tests/baselines/reference/jsDeclarationsImportAliasExposedWithinNamespace.js index d1ba516018e48..b600a72f5cd6b 100644 --- a/tests/baselines/reference/jsDeclarationsImportAliasExposedWithinNamespace.js +++ b/tests/baselines/reference/jsDeclarationsImportAliasExposedWithinNamespace.js @@ -67,7 +67,7 @@ export namespace myTypes { prop2: string; }; type typeC = myTypes.typeB | Function; - const myTypes: { + let myTypes: { [x: string]: any; }; } diff --git a/tests/baselines/reference/jsDeclarationsReactComponents.js b/tests/baselines/reference/jsDeclarationsReactComponents.js index a59bd3b2e6763..d0c4a2415283a 100644 --- a/tests/baselines/reference/jsDeclarationsReactComponents.js +++ b/tests/baselines/reference/jsDeclarationsReactComponents.js @@ -190,10 +190,10 @@ export default TabbedShowLayout; declare function TabbedShowLayout({}: {}): JSX.Element; declare namespace TabbedShowLayout { namespace propTypes { - const version: PropTypes.Requireable; + let version: PropTypes.Requireable; } namespace defaultProps { - const tabs: undefined; + let tabs: undefined; } } import PropTypes from "prop-types"; @@ -224,7 +224,7 @@ declare function TabbedShowLayout(prop: { }): JSX.Element; declare namespace TabbedShowLayout { namespace defaultProps { - const tabs: string; + let tabs: string; } } //// [jsDeclarationsReactComponents5.d.ts] @@ -235,12 +235,12 @@ declare function Tree({ allowDropOnRoot }: { }): JSX.Element; declare namespace Tree { namespace propTypes { - const classes: PropTypes.Requireable; + let classes: PropTypes.Requireable; } namespace defaultProps { - const classes_1: {}; + let classes_1: {}; export { classes_1 as classes }; - export const parentSource: string; + export let parentSource: string; } } import PropTypes from 'prop-types'; diff --git a/tests/baselines/reference/jsDeclarationsTypeReferences3.js b/tests/baselines/reference/jsDeclarationsTypeReferences3.js index ea5f5a225512f..92788f50a67bb 100644 --- a/tests/baselines/reference/jsDeclarationsTypeReferences3.js +++ b/tests/baselines/reference/jsDeclarationsTypeReferences3.js @@ -27,7 +27,7 @@ module.exports.A.B = { /// export namespace A { namespace B { - const thing: Something; + let thing: Something; } } import Something_1 = require("fs"); diff --git a/tests/baselines/reference/jsDeclarationsTypeReferences4.js b/tests/baselines/reference/jsDeclarationsTypeReferences4.js index 063aca33d76f0..b89523214bd6c 100644 --- a/tests/baselines/reference/jsDeclarationsTypeReferences4.js +++ b/tests/baselines/reference/jsDeclarationsTypeReferences4.js @@ -43,6 +43,6 @@ export const Something: 2; export namespace A { namespace B { export { thing }; - export const thing: import("fs").Something; + export let thing: import("fs").Something; } } diff --git a/tests/baselines/reference/jsDeclarationsWithDefaultAsNamespaceLikeMerge.js b/tests/baselines/reference/jsDeclarationsWithDefaultAsNamespaceLikeMerge.js index ce8ba7c2342b5..fbaea7f86741d 100644 --- a/tests/baselines/reference/jsDeclarationsWithDefaultAsNamespaceLikeMerge.js +++ b/tests/baselines/reference/jsDeclarationsWithDefaultAsNamespaceLikeMerge.js @@ -25,7 +25,7 @@ export default { //// [index.d.ts] declare namespace _default { namespace computed { - const panels: import("./helper").Computed; + let panels: import("./helper").Computed; } } export default _default; diff --git a/tests/baselines/reference/jsdocImplements_class.js b/tests/baselines/reference/jsdocImplements_class.js index de40a604ebca7..6ebab5ca74a52 100644 --- a/tests/baselines/reference/jsdocImplements_class.js +++ b/tests/baselines/reference/jsdocImplements_class.js @@ -73,7 +73,7 @@ declare class B3 implements A { } declare namespace Ns { export { C1 }; - export const C5: { + export let C5: { new (): { method(): number; }; diff --git a/tests/baselines/reference/jsdocTemplateTagNameResolution.js b/tests/baselines/reference/jsdocTemplateTagNameResolution.js index 0db2a96eb5505..dc4ac52f084f8 100644 --- a/tests/baselines/reference/jsdocTemplateTagNameResolution.js +++ b/tests/baselines/reference/jsdocTemplateTagNameResolution.js @@ -23,7 +23,7 @@ var y = "a"; //// [file.d.ts] declare namespace x { - const a: number; + let a: number; } /** @type {Foo} */ declare const y: Foo; diff --git a/tests/baselines/reference/jsxDeclarationsWithEsModuleInteropNoCrash.js b/tests/baselines/reference/jsxDeclarationsWithEsModuleInteropNoCrash.js index 19524e13025eb..07eafc0828cf1 100644 --- a/tests/baselines/reference/jsxDeclarationsWithEsModuleInteropNoCrash.js +++ b/tests/baselines/reference/jsxDeclarationsWithEsModuleInteropNoCrash.js @@ -33,10 +33,10 @@ declare namespace Foo { export { defaultProps }; } declare namespace propTypes { - const bar: PropTypes.Requireable; + let bar: PropTypes.Requireable; } declare namespace defaultProps { - const bar_1: boolean; + let bar_1: boolean; export { bar_1 as bar }; } import PropTypes from 'prop-types'; diff --git a/tests/baselines/reference/moduleExportsElementAccessAssignment.js b/tests/baselines/reference/moduleExportsElementAccessAssignment.js index bcaa27ce775ea..ea10f848de660 100644 --- a/tests/baselines/reference/moduleExportsElementAccessAssignment.js +++ b/tests/baselines/reference/moduleExportsElementAccessAssignment.js @@ -21,23 +21,23 @@ mod1.default; //// [mod1.d.ts] export namespace a { - const x: string; + let x: string; } export namespace b { - const x_1: string; + let x_1: string; export { x_1 as x }; } declare namespace _default { - const x_2: string; + let x_2: string; export { x_2 as x }; } export default _default; export namespace c { - const x_3: string; + let x_3: string; export { x_3 as x }; } export namespace d { - const e: number; + let e: number; } //// [mod2.d.ts] export {}; diff --git a/tests/baselines/reference/nestedDestructuringOfRequire.js b/tests/baselines/reference/nestedDestructuringOfRequire.js index 516921273e150..3fbbd7f183f1f 100644 --- a/tests/baselines/reference/nestedDestructuringOfRequire.js +++ b/tests/baselines/reference/nestedDestructuringOfRequire.js @@ -27,7 +27,7 @@ chalk; //// [mod1.d.ts] export namespace chalk { - const grey: {}; + let grey: {}; } //// [main.d.ts] export {}; diff --git a/tests/baselines/reference/requireOfESWithPropertyAccess.js b/tests/baselines/reference/requireOfESWithPropertyAccess.js index ef8ebfded1e8c..345320e6af0a3 100644 --- a/tests/baselines/reference/requireOfESWithPropertyAccess.js +++ b/tests/baselines/reference/requireOfESWithPropertyAccess.js @@ -30,7 +30,7 @@ x.x.grey; //// [ch.d.ts] export namespace x { - const grey: {}; + let grey: {}; } //// [main.d.ts] export {}; diff --git a/tests/baselines/reference/tsbuild/javascriptProjectEmit/modifies-outfile-js-projects-and-concatenates-them-correctly.js b/tests/baselines/reference/tsbuild/javascriptProjectEmit/modifies-outfile-js-projects-and-concatenates-them-correctly.js index 89be1f98e0624..3bd07ed6d0b7e 100644 --- a/tests/baselines/reference/tsbuild/javascriptProjectEmit/modifies-outfile-js-projects-and-concatenates-them-correctly.js +++ b/tests/baselines/reference/tsbuild/javascriptProjectEmit/modifies-outfile-js-projects-and-concatenates-them-correctly.js @@ -381,7 +381,7 @@ type MyNominal = Nominal; */ declare function getVar(): keyof typeof variable; declare namespace variable { - const key: MyNominal; + let key: MyNominal; } @@ -406,7 +406,7 @@ function getVar() { //// [/src/sub-project-2/sub-project-2.tsbuildinfo] -{"bundle":{"commonSourceDirectory":"..","sourceFiles":["./index.js"],"js":{"sections":[{"pos":0,"end":174,"kind":"prepend","data":"../sub-project/sub-project.js","texts":[{"pos":0,"end":174,"kind":"text"}]},{"pos":174,"end":322,"kind":"text"}],"hash":"-4809651809-/**\n * @template T, Name\n * @typedef {T & {[Symbol.species]: Name}} Nominal\n */\n/**\n * @typedef {Nominal} MyNominal\n */\nvar c = /** @type {*} */ (null);\nvar variable = {\n key: /** @type {MyNominal} */ ('value'),\n};\n/**\n * @return {keyof typeof variable}\n */\nfunction getVar() {\n return 'key';\n}\n"},"dts":{"sections":[{"pos":0,"end":191,"kind":"prepend","data":"../sub-project/sub-project.d.ts","texts":[{"pos":0,"end":191,"kind":"text"}]},{"pos":191,"end":341,"kind":"text"}],"hash":"4681612701-type Nominal = T & {\n [Symbol.species]: Name;\n};\n/**\n * @typedef {Nominal} MyNominal\n */\ndeclare const c: any;\ntype MyNominal = Nominal;\n/**\n * @return {keyof typeof variable}\n */\ndeclare function getVar(): keyof typeof variable;\ndeclare namespace variable {\n const key: MyNominal;\n}\n"}},"program":{"fileNames":["../../lib/lib.d.ts","../sub-project/sub-project.d.ts","./index.js"],"fileInfos":["-32082413277-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ndeclare const console: { log(msg: any): void; };\ninterface SymbolConstructor {\n readonly species: symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\n","-9550245654-type Nominal = T & {\n [Symbol.species]: Name;\n};\n/**\n * @typedef {Nominal} MyNominal\n */\ndeclare const c: any;\ntype MyNominal = Nominal;\n","2078909278-const variable = {\n key: /** @type {MyNominal} */('value'),\n};\n\n/**\n * @return {keyof typeof variable}\n */\nfunction getVar() {\n return 'key';\n}\n"],"root":[3],"options":{"composite":true,"declaration":true,"outFile":"./sub-project-2.js","rootDir":"..","skipLibCheck":true},"outSignature":"4681612701-type Nominal = T & {\n [Symbol.species]: Name;\n};\n/**\n * @typedef {Nominal} MyNominal\n */\ndeclare const c: any;\ntype MyNominal = Nominal;\n/**\n * @return {keyof typeof variable}\n */\ndeclare function getVar(): keyof typeof variable;\ndeclare namespace variable {\n const key: MyNominal;\n}\n","latestChangedDtsFile":"./sub-project-2.d.ts"},"version":"FakeTSVersion"} +{"bundle":{"commonSourceDirectory":"..","sourceFiles":["./index.js"],"js":{"sections":[{"pos":0,"end":174,"kind":"prepend","data":"../sub-project/sub-project.js","texts":[{"pos":0,"end":174,"kind":"text"}]},{"pos":174,"end":322,"kind":"text"}],"hash":"-4809651809-/**\n * @template T, Name\n * @typedef {T & {[Symbol.species]: Name}} Nominal\n */\n/**\n * @typedef {Nominal} MyNominal\n */\nvar c = /** @type {*} */ (null);\nvar variable = {\n key: /** @type {MyNominal} */ ('value'),\n};\n/**\n * @return {keyof typeof variable}\n */\nfunction getVar() {\n return 'key';\n}\n"},"dts":{"sections":[{"pos":0,"end":191,"kind":"prepend","data":"../sub-project/sub-project.d.ts","texts":[{"pos":0,"end":191,"kind":"text"}]},{"pos":191,"end":339,"kind":"text"}],"hash":"-308335141-type Nominal = T & {\n [Symbol.species]: Name;\n};\n/**\n * @typedef {Nominal} MyNominal\n */\ndeclare const c: any;\ntype MyNominal = Nominal;\n/**\n * @return {keyof typeof variable}\n */\ndeclare function getVar(): keyof typeof variable;\ndeclare namespace variable {\n let key: MyNominal;\n}\n"}},"program":{"fileNames":["../../lib/lib.d.ts","../sub-project/sub-project.d.ts","./index.js"],"fileInfos":["-32082413277-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ndeclare const console: { log(msg: any): void; };\ninterface SymbolConstructor {\n readonly species: symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\n","-9550245654-type Nominal = T & {\n [Symbol.species]: Name;\n};\n/**\n * @typedef {Nominal} MyNominal\n */\ndeclare const c: any;\ntype MyNominal = Nominal;\n","2078909278-const variable = {\n key: /** @type {MyNominal} */('value'),\n};\n\n/**\n * @return {keyof typeof variable}\n */\nfunction getVar() {\n return 'key';\n}\n"],"root":[3],"options":{"composite":true,"declaration":true,"outFile":"./sub-project-2.js","rootDir":"..","skipLibCheck":true},"outSignature":"-308335141-type Nominal = T & {\n [Symbol.species]: Name;\n};\n/**\n * @typedef {Nominal} MyNominal\n */\ndeclare const c: any;\ntype MyNominal = Nominal;\n/**\n * @return {keyof typeof variable}\n */\ndeclare function getVar(): keyof typeof variable;\ndeclare namespace variable {\n let key: MyNominal;\n}\n","latestChangedDtsFile":"./sub-project-2.d.ts"},"version":"FakeTSVersion"} //// [/src/sub-project-2/sub-project-2.tsbuildinfo.baseline.txt] ====================================================================== @@ -453,13 +453,13 @@ declare const c: any; type MyNominal = Nominal; ---------------------------------------------------------------------- -text: (191-341) +text: (191-339) /** * @return {keyof typeof variable} */ declare function getVar(): keyof typeof variable; declare namespace variable { - const key: MyNominal; + let key: MyNominal; } ====================================================================== @@ -511,11 +511,11 @@ declare namespace variable { }, { "pos": 191, - "end": 341, + "end": 339, "kind": "text" } ], - "hash": "4681612701-type Nominal = T & {\n [Symbol.species]: Name;\n};\n/**\n * @typedef {Nominal} MyNominal\n */\ndeclare const c: any;\ntype MyNominal = Nominal;\n/**\n * @return {keyof typeof variable}\n */\ndeclare function getVar(): keyof typeof variable;\ndeclare namespace variable {\n const key: MyNominal;\n}\n" + "hash": "-308335141-type Nominal = T & {\n [Symbol.species]: Name;\n};\n/**\n * @typedef {Nominal} MyNominal\n */\ndeclare const c: any;\ntype MyNominal = Nominal;\n/**\n * @return {keyof typeof variable}\n */\ndeclare function getVar(): keyof typeof variable;\ndeclare namespace variable {\n let key: MyNominal;\n}\n" } }, "program": { @@ -542,11 +542,11 @@ declare namespace variable { "rootDir": "..", "skipLibCheck": true }, - "outSignature": "4681612701-type Nominal = T & {\n [Symbol.species]: Name;\n};\n/**\n * @typedef {Nominal} MyNominal\n */\ndeclare const c: any;\ntype MyNominal = Nominal;\n/**\n * @return {keyof typeof variable}\n */\ndeclare function getVar(): keyof typeof variable;\ndeclare namespace variable {\n const key: MyNominal;\n}\n", + "outSignature": "-308335141-type Nominal = T & {\n [Symbol.species]: Name;\n};\n/**\n * @typedef {Nominal} MyNominal\n */\ndeclare const c: any;\ntype MyNominal = Nominal;\n/**\n * @return {keyof typeof variable}\n */\ndeclare function getVar(): keyof typeof variable;\ndeclare namespace variable {\n let key: MyNominal;\n}\n", "latestChangedDtsFile": "./sub-project-2.d.ts" }, "version": "FakeTSVersion", - "size": 2893 + "size": 2889 } @@ -727,7 +727,7 @@ function getVar() { //// [/src/sub-project-2/sub-project-2.tsbuildinfo] -{"bundle":{"commonSourceDirectory":"..","sourceFiles":["./index.js"],"js":{"sections":[{"pos":0,"end":179,"kind":"prepend","data":"../sub-project/sub-project.js","texts":[{"pos":0,"end":179,"kind":"text"}]},{"pos":179,"end":327,"kind":"text"}],"hash":"-26783073610-/**\n * @template T, Name\n * @typedef {T & {[Symbol.species]: Name}} Nominal\n */\n/**\n * @typedef {Nominal} MyNominal\n */\nvar c = /** @type {*} */ (undefined);\nvar variable = {\n key: /** @type {MyNominal} */ ('value'),\n};\n/**\n * @return {keyof typeof variable}\n */\nfunction getVar() {\n return 'key';\n}\n"},"dts":{"sections":[{"pos":0,"end":191,"kind":"prepend","data":"../sub-project/sub-project.d.ts","texts":[{"pos":0,"end":191,"kind":"text"}]},{"pos":191,"end":341,"kind":"text"}],"hash":"4681612701-type Nominal = T & {\n [Symbol.species]: Name;\n};\n/**\n * @typedef {Nominal} MyNominal\n */\ndeclare const c: any;\ntype MyNominal = Nominal;\n/**\n * @return {keyof typeof variable}\n */\ndeclare function getVar(): keyof typeof variable;\ndeclare namespace variable {\n const key: MyNominal;\n}\n"}},"program":{"fileNames":["../../lib/lib.d.ts","../sub-project/sub-project.d.ts","./index.js"],"fileInfos":["-32082413277-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ndeclare const console: { log(msg: any): void; };\ninterface SymbolConstructor {\n readonly species: symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\n","-9550245654-type Nominal = T & {\n [Symbol.species]: Name;\n};\n/**\n * @typedef {Nominal} MyNominal\n */\ndeclare const c: any;\ntype MyNominal = Nominal;\n","2078909278-const variable = {\n key: /** @type {MyNominal} */('value'),\n};\n\n/**\n * @return {keyof typeof variable}\n */\nfunction getVar() {\n return 'key';\n}\n"],"root":[3],"options":{"composite":true,"declaration":true,"outFile":"./sub-project-2.js","rootDir":"..","skipLibCheck":true},"outSignature":"4681612701-type Nominal = T & {\n [Symbol.species]: Name;\n};\n/**\n * @typedef {Nominal} MyNominal\n */\ndeclare const c: any;\ntype MyNominal = Nominal;\n/**\n * @return {keyof typeof variable}\n */\ndeclare function getVar(): keyof typeof variable;\ndeclare namespace variable {\n const key: MyNominal;\n}\n","latestChangedDtsFile":"./sub-project-2.d.ts"},"version":"FakeTSVersion"} +{"bundle":{"commonSourceDirectory":"..","sourceFiles":["./index.js"],"js":{"sections":[{"pos":0,"end":179,"kind":"prepend","data":"../sub-project/sub-project.js","texts":[{"pos":0,"end":179,"kind":"text"}]},{"pos":179,"end":327,"kind":"text"}],"hash":"-26783073610-/**\n * @template T, Name\n * @typedef {T & {[Symbol.species]: Name}} Nominal\n */\n/**\n * @typedef {Nominal} MyNominal\n */\nvar c = /** @type {*} */ (undefined);\nvar variable = {\n key: /** @type {MyNominal} */ ('value'),\n};\n/**\n * @return {keyof typeof variable}\n */\nfunction getVar() {\n return 'key';\n}\n"},"dts":{"sections":[{"pos":0,"end":191,"kind":"prepend","data":"../sub-project/sub-project.d.ts","texts":[{"pos":0,"end":191,"kind":"text"}]},{"pos":191,"end":339,"kind":"text"}],"hash":"-308335141-type Nominal = T & {\n [Symbol.species]: Name;\n};\n/**\n * @typedef {Nominal} MyNominal\n */\ndeclare const c: any;\ntype MyNominal = Nominal;\n/**\n * @return {keyof typeof variable}\n */\ndeclare function getVar(): keyof typeof variable;\ndeclare namespace variable {\n let key: MyNominal;\n}\n"}},"program":{"fileNames":["../../lib/lib.d.ts","../sub-project/sub-project.d.ts","./index.js"],"fileInfos":["-32082413277-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ndeclare const console: { log(msg: any): void; };\ninterface SymbolConstructor {\n readonly species: symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\n","-9550245654-type Nominal = T & {\n [Symbol.species]: Name;\n};\n/**\n * @typedef {Nominal} MyNominal\n */\ndeclare const c: any;\ntype MyNominal = Nominal;\n","2078909278-const variable = {\n key: /** @type {MyNominal} */('value'),\n};\n\n/**\n * @return {keyof typeof variable}\n */\nfunction getVar() {\n return 'key';\n}\n"],"root":[3],"options":{"composite":true,"declaration":true,"outFile":"./sub-project-2.js","rootDir":"..","skipLibCheck":true},"outSignature":"-308335141-type Nominal = T & {\n [Symbol.species]: Name;\n};\n/**\n * @typedef {Nominal} MyNominal\n */\ndeclare const c: any;\ntype MyNominal = Nominal;\n/**\n * @return {keyof typeof variable}\n */\ndeclare function getVar(): keyof typeof variable;\ndeclare namespace variable {\n let key: MyNominal;\n}\n","latestChangedDtsFile":"./sub-project-2.d.ts"},"version":"FakeTSVersion"} //// [/src/sub-project-2/sub-project-2.tsbuildinfo.baseline.txt] ====================================================================== @@ -774,13 +774,13 @@ declare const c: any; type MyNominal = Nominal; ---------------------------------------------------------------------- -text: (191-341) +text: (191-339) /** * @return {keyof typeof variable} */ declare function getVar(): keyof typeof variable; declare namespace variable { - const key: MyNominal; + let key: MyNominal; } ====================================================================== @@ -832,11 +832,11 @@ declare namespace variable { }, { "pos": 191, - "end": 341, + "end": 339, "kind": "text" } ], - "hash": "4681612701-type Nominal = T & {\n [Symbol.species]: Name;\n};\n/**\n * @typedef {Nominal} MyNominal\n */\ndeclare const c: any;\ntype MyNominal = Nominal;\n/**\n * @return {keyof typeof variable}\n */\ndeclare function getVar(): keyof typeof variable;\ndeclare namespace variable {\n const key: MyNominal;\n}\n" + "hash": "-308335141-type Nominal = T & {\n [Symbol.species]: Name;\n};\n/**\n * @typedef {Nominal} MyNominal\n */\ndeclare const c: any;\ntype MyNominal = Nominal;\n/**\n * @return {keyof typeof variable}\n */\ndeclare function getVar(): keyof typeof variable;\ndeclare namespace variable {\n let key: MyNominal;\n}\n" } }, "program": { @@ -863,10 +863,10 @@ declare namespace variable { "rootDir": "..", "skipLibCheck": true }, - "outSignature": "4681612701-type Nominal = T & {\n [Symbol.species]: Name;\n};\n/**\n * @typedef {Nominal} MyNominal\n */\ndeclare const c: any;\ntype MyNominal = Nominal;\n/**\n * @return {keyof typeof variable}\n */\ndeclare function getVar(): keyof typeof variable;\ndeclare namespace variable {\n const key: MyNominal;\n}\n", + "outSignature": "-308335141-type Nominal = T & {\n [Symbol.species]: Name;\n};\n/**\n * @typedef {Nominal} MyNominal\n */\ndeclare const c: any;\ntype MyNominal = Nominal;\n/**\n * @return {keyof typeof variable}\n */\ndeclare function getVar(): keyof typeof variable;\ndeclare namespace variable {\n let key: MyNominal;\n}\n", "latestChangedDtsFile": "./sub-project-2.d.ts" }, "version": "FakeTSVersion", - "size": 2899 + "size": 2895 } diff --git a/tests/baselines/reference/typeFromPropertyAssignment39.js b/tests/baselines/reference/typeFromPropertyAssignment39.js index fb477aca063b9..04e125938ac87 100644 --- a/tests/baselines/reference/typeFromPropertyAssignment39.js +++ b/tests/baselines/reference/typeFromPropertyAssignment39.js @@ -9,6 +9,6 @@ foo["baz"]["blah"] = 3; //// [a.d.ts] declare namespace foo { namespace baz { - const blah: number; + let blah: number; } } diff --git a/tests/cases/conformance/jsdoc/declarations/jsDeclarationsClassStatic2.ts b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsClassStatic2.ts new file mode 100644 index 0000000000000..519c7e591028d --- /dev/null +++ b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsClassStatic2.ts @@ -0,0 +1,17 @@ +// @allowJs: true +// @checkJs: true +// @declaration: true +// @emitDeclarationOnly: true +// @outDir: ./out/ +// @filename: Foo.js +class Base { + static foo = ""; +} +export class Foo extends Base {} +Foo.foo = "foo"; + +// @filename: Bar.ts +import { Foo } from "./Foo.js"; + +class Bar extends Foo {} +Bar.foo = "foo";