microsoft / microsoft/TypeScript
jsdoc in JS: arguments object does not infer types from the containing function
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.3k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 117
Beschreibung
🔎 Search Terms
argument object infer
🕗 Version & Regression Information
I see it in next but I'm sure it's the way it's always behaved.
⏯ Playground Link
💻 Code
/** @type {(obj: Record<PropertyKey, unknown>, property: PropertyKey, value: unknown, nonEnumerable?: boolean | null, nonWritable?: boolean | null, nonConfigurable?: boolean | null, loose?: boolean) => void} */
module.exports = function defineDataProperty(
obj,
property,
value
) {
if (!obj || (typeof obj !== 'object' && typeof obj !== 'function')) {
throw new TypeError('`obj` must be an object or a function`');
}
if (typeof property !== 'string' && typeof property !== 'symbol') {
throw new TypeError('`property` must be a string or a symbol`');
}
if (arguments.length > 3 && typeof arguments[3] !== 'boolean' && arguments[3] !== null) {
throw new TypeError('`nonEnumerable`, if provided, must be a boolean or null');
}
if (arguments.length > 4 && typeof arguments[4] !== 'boolean' && arguments[4] !== null) {
throw new TypeError('`nonWritable`, if provided, must be a boolean or null');
}
if (arguments.length > 5 && typeof arguments[5] !== 'boolean' && arguments[5] !== null) {
throw new TypeError('`nonConfigurable`, if provided, must be a boolean or null');
}
if (arguments.length > 6 && typeof arguments[6] !== 'boolean') {
throw new TypeError('`loose`, if provided, must be a boolean');
}
var nonEnumerable = arguments.length > 3 ? arguments[3] : null;
var nonWritable = arguments.length > 4 ? arguments[4] : null;
var nonConfigurable = arguments.length > 5 ? arguments[5] : null;
var loose = arguments.length > 6 ? arguments[6] : false;
};
🙂 Expected behavior
arguments[3] (and 4, 5, and 6) should all have a type as defined in the function's type (in this case, boolean | null for the first three, and boolean for the fourth).
This should result in nonEnumerable, nonWritable, and nonConfigurable being of type boolean | null, and loose being of type boolean.
🙁 Actual behavior
Those four variables have a type of any.
Additional information about the issue
This is using jsdoc in a .js file with allowJs/checkJs enabled.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne mit dem verknüpften TypeScript Playground und reproduziere die inferierten Typen für arguments[3] bis arguments[6] im gezeigten JavaScript-Beispiel. Verfolge die Behandlung von JSDoc-Funktionstypen und dem arguments-Objekt durch den Checker und füge anschließend einen Regressionstest hinzu. Die Aufgabe ist abgeschlossen, wenn für diese indizierten Argumente wie angegeben boolean | null oder boolean statt any inferiert wird.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- javascript, typescript
- Bereich
- compilers
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 38/100