Сообщение от safohubo
|
В JS же нельзя первый параметр пропускать или нет?
|
можно, с небольшим костыликом
function func(tabId, details) {
if (typeof tabId !== 'number') {
details = tabId;
tabId = undefined;
}
console.log('tabId, details:', tabId, details);
}
чтобы это обрисовать в тайпскрипте, надо будет сделать перегрузку функции:
function func(tabId: number, details: object): void;
function func(details: object): void;
function func(...a: [number, object] | [object]): void {
const [tabId, details] = a.length === 1 ? [undefined, a[0]] : a;
// tabId: number | undefined
// details: object
console.log('tabId, details:', tabId, details);
}