Resolves a selector parameter into a function that extracts a value from an item.
The selector can be:
The type of the input items.
The type of the selected value.
Optional
The selector key or function.
A fallback function if no selector is provided.
Name used in error messages.
The resolved selector function.
const sel1 = resolveSelector<{name: string}, string>('name');sel1({name: 'Alice'}); // 'Alice'const sel2 = resolveSelector<{value: number}, number>(item => item.value * 2);sel2({value: 5}); // 10const sel3 = resolveSelector(undefined, (item) => item.toString());sel3(42); // '42' Copy
const sel1 = resolveSelector<{name: string}, string>('name');sel1({name: 'Alice'}); // 'Alice'const sel2 = resolveSelector<{value: number}, number>(item => item.value * 2);sel2({value: 5}); // 10const sel3 = resolveSelector(undefined, (item) => item.toString());sel3(42); // '42'
If the selector is not a function or string key.
If no selector is provided and no fallback is given.
Resolves a selector parameter into a function that extracts a value from an item.
The selector can be: