Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion internal/checker/nodebuilderimpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -2160,7 +2160,15 @@ func (b *NodeBuilderImpl) indexInfoToIndexSignatureDeclarationHelper(indexInfo *
}

func hasTypeAnnotation(declaration *ast.Declaration) bool {
return declaration != nil && declaration.Type() != nil
if declaration == nil || declaration.Type() == nil {
return false
}
// Type alias declarations have a .Type() that is their type definition, not a type annotation on a value.
// Exclude them so callers don't mistake them for annotated value declarations.
if ast.IsTypeAliasDeclaration(declaration) || ast.IsJSTypeAliasDeclaration(declaration) {
return false
}
return true
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
local-lib/ModuleGraphConnection.js(3,1): error TS2309: An export assignment cannot be used in a module with other exported elements.
local-lib/ModuleGraphConnection.js(4,16): error TS2339: Property 'T' does not exist on type 'typeof ModuleGraphConnection'.


==== local-lib/ModuleGraphConnection.js (2 errors) ====
/** @typedef {typeof T} T */
const T = Symbol();
module.exports = class ModuleGraphConnection {};
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2309: An export assignment cannot be used in a module with other exported elements.
module.exports.T = T;
~
!!! error TS2339: Property 'T' does not exist on type 'typeof ModuleGraphConnection'.

==== repro.js (0 errors) ====
'use strict';
/** @typedef {import('./local-lib/ModuleGraphConnection')} ImportedType */
/** @type {ImportedType} */
module.exports = class Repro {};

Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//// [tests/cases/compiler/jsTypedefMergedWithModuleExportProperty.ts] ////

//// [ModuleGraphConnection.js]
/** @typedef {typeof T} T */
const T = Symbol();
module.exports = class ModuleGraphConnection {};
module.exports.T = T;

//// [repro.js]
'use strict';
/** @typedef {import('./local-lib/ModuleGraphConnection')} ImportedType */
/** @type {ImportedType} */
module.exports = class Repro {};


//// [ModuleGraphConnection.js]
"use strict";
/** @typedef {typeof T} T */
const T = Symbol();
module.exports = class ModuleGraphConnection {
};
module.exports.T = T;
//// [repro.js]
'use strict';
/** @typedef {import('./local-lib/ModuleGraphConnection')} ImportedType */
/** @type {ImportedType} */
module.exports = class Repro {
};


//// [ModuleGraphConnection.d.ts]
export = ModuleGraphConnection;
declare class ModuleGraphConnection {
}
declare namespace ModuleGraphConnection {
const _exported: typeof T;
export { _exported as T };
}
export type T = typeof T;
/** @typedef {typeof T} T */
declare const T: unique symbol;
//// [repro.d.ts]
export = Repro;
/** @typedef {import('./local-lib/ModuleGraphConnection')} ImportedType */
/** @type {ImportedType} */
declare class Repro {
}
export type ImportedType = import('./local-lib/ModuleGraphConnection');
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//// [tests/cases/compiler/jsTypedefMergedWithModuleExportProperty.ts] ////

=== local-lib/ModuleGraphConnection.js ===
/** @typedef {typeof T} T */
const T = Symbol();
>T : Symbol(T, Decl(ModuleGraphConnection.js, 1, 5), Decl(ModuleGraphConnection.js, 0, 4))
>Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --))

module.exports = class ModuleGraphConnection {};
>module.exports : Symbol(exports, Decl(ModuleGraphConnection.js, 0, 0))
>module : Symbol(module, Decl(ModuleGraphConnection.js, 0, 0))
>exports : Symbol(exports, Decl(ModuleGraphConnection.js, 0, 0))
>ModuleGraphConnection : Symbol(ModuleGraphConnection, Decl(ModuleGraphConnection.js, 2, 16))

module.exports.T = T;
>module.exports : Symbol(exports, Decl(ModuleGraphConnection.js, 0, 0))
>module : Symbol(module, Decl(ModuleGraphConnection.js, 0, 0))
>exports : Symbol(exports, Decl(ModuleGraphConnection.js, 0, 0))
>T : Symbol(T, Decl(ModuleGraphConnection.js, 1, 5), Decl(ModuleGraphConnection.js, 0, 4))

=== repro.js ===
'use strict';
/** @typedef {import('./local-lib/ModuleGraphConnection')} ImportedType */
/** @type {ImportedType} */
module.exports = class Repro {};
>module.exports : Symbol(exports, Decl(repro.js, 0, 0))
>module : Symbol(module, Decl(repro.js, 0, 0))
>exports : Symbol(exports, Decl(repro.js, 0, 0))
>Repro : Symbol(Repro, Decl(repro.js, 3, 16))

Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//// [tests/cases/compiler/jsTypedefMergedWithModuleExportProperty.ts] ////

=== local-lib/ModuleGraphConnection.js ===
/** @typedef {typeof T} T */
const T = Symbol();
>T : unique symbol
>Symbol() : unique symbol
>Symbol : SymbolConstructor

module.exports = class ModuleGraphConnection {};
>module.exports = class ModuleGraphConnection {} : typeof ModuleGraphConnection
>module.exports : typeof ModuleGraphConnection
>module : { exports: typeof ModuleGraphConnection; }
>exports : typeof ModuleGraphConnection
>class ModuleGraphConnection {} : typeof ModuleGraphConnection
>ModuleGraphConnection : typeof ModuleGraphConnection

module.exports.T = T;
>module.exports.T = T : unique symbol
>module.exports.T : any
>module.exports : typeof ModuleGraphConnection
>module : { exports: typeof ModuleGraphConnection; }
>exports : typeof ModuleGraphConnection
>T : any
>T : unique symbol

=== repro.js ===
'use strict';
>'use strict' : "use strict"

/** @typedef {import('./local-lib/ModuleGraphConnection')} ImportedType */
/** @type {ImportedType} */
module.exports = class Repro {};
>module.exports = class Repro {} : typeof Repro
>module.exports : typeof Repro
>module : { exports: typeof Repro; }
>exports : typeof Repro
>class Repro {} : typeof Repro
>Repro : typeof Repro

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// @allowJs: true
// @checkJs: true
// @target: es2015
// @outDir: ./out
// @declaration: true

// @filename: local-lib/ModuleGraphConnection.js
/** @typedef {typeof T} T */
const T = Symbol();
module.exports = class ModuleGraphConnection {};
module.exports.T = T;

// @filename: repro.js
'use strict';
/** @typedef {import('./local-lib/ModuleGraphConnection')} ImportedType */
/** @type {ImportedType} */
module.exports = class Repro {};