Skip to content

Utility Parameters type cast tuple type elements to optional #42555

@maksimr

Description

@maksimr

TypeScript 4.1.3

    /**
     * @template {function} T
     * @param {T} fn
     * @returns {(...args: Parameters<T>) => void}
     */
    function throttle(fn) {
      return (...args) => {
        fn(...args);
      };
    }

    const tfn = throttle((/**@type {string}*/x) => x);
    tfn(); // NO ERROR (WRONG)
    tfn("foo") // No error (Right!)
    tfn(1); // Error (Right!)
    tfn("foo", 2); // Error (Right!)

tsconfig.json

{
  "compilerOptions": {
    "target": "es6",
    "jsx": "react",
    "allowJs": true,
    "checkJs": true,
    "noEmit": true,
    "skipLibCheck": true,
    "strict": true,
    "noImplicitAny": false,
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "allowSyntheticDefaultImports": true,
    "typeRoots": [
      "./node_modules/@types",
      "./@types"
    ]
  },
  "include": [
    "@types/**/*",
    "lib"
  ],
  "exclude": [
    "node_modules"
  ]
}

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions