-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Open
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: JSDocRelates to JSDoc parsing and type generationRelates to JSDoc parsing and type generation
Milestone
Description
TypeScript Version: 3.1.4
Search Terms: mapped type parameters js
Code
// TypeScript
const Foo = Object.freeze({
a: (arg1: string) => arg1,
b: (arg1: string, arg2: boolean) => arg2,
});
// typeof Foo = Readonly<{
// a: (arg1: string) => string;
// b: (arg1: string, arg2: boolean) => boolean;
//}>
type Bar = {[K in keyof typeof Foo]: (...args: Parameters<(typeof Foo)[K]>) => void}
// typeof Bar = {
// readonly a: (arg1: string) => void;
// readonly b: (arg1: string, arg2: boolean) => void;
// }// JavaScript
const Foo = Object.freeze({
a: (/** @type {string} */arg1) => arg1,
b: (/** @type {string} */arg1, /** @type {boolean} */arg2) => arg2,
});
// typeof Foo = Readonly<{
// a: (arg1: string) => string;
// b: (arg1: string, arg2: boolean) => boolean;
//}>
// ^ is identical to TS
/** @typedef {{[K in keyof typeof Foo]: (...args: Parameters<(typeof Foo)[K]>) => void}} Bar */
// typeof Bar = {
// readonly a: (arg1?: string) => void;
// readonly b: (arg1?: string, arg2?: boolean) => void;
// }
// ^ why optional??Expected behavior:
Bar.{a,b} having the same signatures in TS and JS
Actual behavior:
Bar.{a,b} have only optional parameters in JS.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: JSDocRelates to JSDoc parsing and type generationRelates to JSDoc parsing and type generation