TS Confuses namespace with the class on JSDoc module.exported class with static method.
@sandersn ci sta già lavorando.
Dal 4/10/2023.
Valutazione
Questa issue non è ancora stata valutata.
Descrizione
🔎 Search Terms
"module.exports static method" "namespace vs class confusion" "namespace vs class collision" "Two different types with this name exist, but they are unrelated."
🕗 Version & Regression Information
Versions tried:
- Version 5.3.0-dev (55d8bed85c11672b2b6f9ee3e6e1d384bef6f4da - )
- Version 5.2.2
- Version 5.1.6
- Version 5.0.4
- Version 4.9.5
⏯ Playground Link
💻 Code
// @filename: name.js
'use strict';
/**
* Options for the netaddress.
* @typedef {Object} NameOptions
* @property {String} name
*/
/**
* Net Address
* Represents a network address.
*/
class Name {
/** @type {String} */
name;
/**
* Create a network address.
*/
constructor() {
this.name = 'test';
}
/**
* Inject properties from host, port, and network.
* @param {String} name
* @returns {this}
*/
fromName(name) {
this.name = name;
return this;
}
/**
* @param {String} name
* @returns {Name}
*/
static fromName(name) {
return new this().fromName(name);
}
}
/*
* Expose
*/
module.exports = Name;
// @filename: usage.js
'use strict';
const Name = require('./name');
/** @type {Name} */
let address;
address = new Name();
address.name = 'somename';
🙁 Actual behavior
This reports an error:
Type 'import("/name")' is not assignable to type 'import("/name")'. Two different types with this name exist, but they are unrelated.
The types returned by 'fromName(...)' are incompatible between these types.
Type 'Name' is not assignable to type 'this'.
'Name' is assignable to the constraint of type 'this', but 'this' could be instantiated with a different subtype of constraint 'Name'.
🙂 Expected behavior
new Name() and @type {Name} should be the same as module.exports = Name class.
Additional information about the issue
Repository format: https://github.com/nodech/type-tsjs-tests
generated declaration file for name.js is in the form:
export = Name;
declare class Name {...}
declare namespace Name { export { NameOptions } }
type NameOptions
If you remove @typedef {Object} NameOptions from the name.js, the declaration becomes
export = Name;
declare class Name {...`
and issue goes away.
More confusing
If you leave NameOptions but remove static member static fromName of the class Name, it still has namespace and class with the same name, BUT issue goes away ?
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.4k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di microsoft/TypeScript
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
microsoft/TypeScript#64322 · 2 commenti · 1 reazione · 2 assegnatari ·
-
Possible Improvement
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
microsoft/TypeScript#64278 · 1 commento · 1 reazione ·
-
Docs
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
microsoft/TypeScript#64118 · 1 commento ·
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
microsoft/TypeScript#64094 ·
-
Docs
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
microsoft/TypeScript#63959 · 5 commenti ·
Tutte le issue di microsoft/TypeScript
Issue simili
-
optimization optimization:agents-md-curator
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
githubnext/gh-aw-cao#13143 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
blinklabs-io/bursa#904 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
yanet-platform/ipfw-go#129 ·
-
bug confmap/provider/googlesecretmanagerprovider needs triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
open-telemetry/opentelemetry-collector-contrib#51273 · 2 commenti ·
-
bug: AI Gateway client filter lists "Unknown" twice when NULL and literal Unknown clients coexist Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 90/100