可选参数和剩余参数

在比较函数的兼容性时,可选参数和必需参数是可以互换的。源类型的额外可选参数不出错,源类型中没有对应参数的目标类型可选参数也不出错。

When comparing functions for compatibility, optional and required parameters are interchangeable. Extra optional parameters of the source type are not an error, and optional parameters of the target type without corresponding parameters in the source type are not an error.

+U/CnZBkF9MSQFL3Il2/ePy/UVwwG+ngcnfmHzZ91yR/0TQ8E6GxxRNJQpQeCXmAW+En2eBFkRh5mlOk4JVSFx6Ug4VUfuqKJ1JXOxGRkLJNrWzj1cJWETts8JdraHOeUZ2aS2AiLT0tkRr+I0CphbjIrysTzwC4j4P0ZE3HV8fUcHtjr7k8nAEL2cBSoWdJxVZ2zIQGUV8VWmztEV+mAX4z+tneoMdntyDCdNIiG0bO067MVWUsi+IBwP/ld1nOX5NbVcnewLZPgv/+Os/l4y7jqAuPv+uZP/54sGVOysQ=

LGum+7eJTxOwpekVj5TTLIH6dXqYLXnjjj0xyO2JgcSkLtyvjRH35VQx0AUBrgzSuTEzirOEOQJu3vGuO9tS7iWwcwSi0pHEVJxbYGTYK65rLYZlxWZCEhA8QGu5xBpf/ce/WuYYK22dSD4HfbfTayn3Gz7kFJGrN+aSeVAaq27zBGCT+8IOFnaXycz7qhlaWIMzoMYJ/iKlLncrioYYn3wL6DdGeP5mIZ+vNYMJ/XRN+EbG/v7DC3k9uh0Pz6y+C8V8kEyadLEP6m90RGW82agO9hY5oUPHgMFNiavG2oOKKiTcbsaXpFjHJlx/ILnq4H6yI+iyjS5gtxvKQZZveMxEdPLZiUogEbNSrameLbgFbBVI4HzgZR/cEOaM3ctUA65hEr14k+E5YbpGoIJGZqgdzKcNJ7ASGtzSTKSesvCdnBexsEumFEQWTRL4j3Mk2j0sL1KNUWfj5xVhH7IAjaLuG32PH7TIwnOLqjt2tgg3mee6xxa2/YfMtoBL4W7De0ojrAistnoXh5+NlJK0Jtx+FtN4KZboVEOCxOXpVMcyPhXUJ5PJr3l6d5cN/ZoDfPP4N2cJBPaB0Qg0G5GGkr4wQm4lX7AwCd4ogAHroIJOZVmMp2NgUL6CFdT0Y+co3G/KEmPU5GxXrzoMEGuS2g==

XF2cEdyzrG5TY+6JnsRrnXksNC1AiasD/72p/blxgbK42EM0a4ZW0ytdUIg9LnaZ3r9zn7FkRwyeu6rfJNUc8A4i2FC6mXHKcYeBIPCe7BKHJvZLbCjfjYZhQ9kqquO6SiGGg+/z3DB/FEWXDOqhDMnuGu/nf+gZTN6lKEDKRjv8xS3MjRL2WWT8hmJiKOq58T80e9nUYApt2Pi137ypmuphoJrVnxFnzRqrVnsu8Pgx9kZJtIdDH98QH9FtPnIz3YT8IE6f9GrRJYSw8uQqLQqdSXsczjqeU0BOzX4pCleowjRm/aykihwkDLVdWrdPRri4Gozg+093/uu998VLzoxlV7cIUjwa/y5T7nCiqKR8C5DrLyeshwOxfp7ldhVUz0XB5cZ2u8D9RVDiB+SW3pr460Y5zWO7gapqDjKSRli4pAU/lGBavDQ/yhIjZLN8IzntdSW1FLoAM48gwqctLCnNOIlAo6w8wZfBgfzcN0ploUOiUV7vrMe+YtuZPaTSerbfXJOeMZxpCpzDVXb9jg==

function invokeLater(args: any[], callback: (...args: any[]) => void) {
  /* ... Invoke callback with 'args' ... */
}

// Unsound - invokeLater "might" provide any number of arguments
invokeLater([1, 2], (x, y) => console.log(x + ", " + y));

// Confusing (x and y are actually required) and undiscoverable
invokeLater([1, 2], (x?, y?) => console.log(x + ", " + y));