export function getDocuments<T>(slug: ''): Promise<T[]>;
export function getDocuments<T>(slug: string): Promise<T>;
export function getDocuments<T>(): Promise<T[]>;
export function getDocuments(slug = ''): Promise<unknown> {
const endpoint = `/documents/${slug}`
return getPosts(endpoint);
}
class DataService {
method(callsStore) {
...
callsStore.setCall(...);
}
}
export const setFrame = (titlle: string): setFrameActionType => ({ type: 'SETFRAME', payload: { titlle } });
const columns = [
{
key: "name",
label: "NAME",
},
{
key: "role",
label: "ROLE",
},
{
key: "status",
label: "STATUS",
},
] as const;
type ColumnsType = typeof columns;
const rows: Array<Record<ColumnsType[number]['key'], string> & {key: string}> = [
{
key: "1",
name: "Tony Reichert",
role: "CEO",
status: "Active",
},
{
key: "2",
name: "Zoey Lang",
role: "Technical Lead",
status: "Paused",
},
];
const [field, updateField] = useReducer(fieldReducer, []);
работает без ошибок, применяется перегрузкаfunction useReducer<R extends Reducer<any, any>>(
reducer: R,
initialState: ReducerState<R>,
initializer?: undefined
): [ReducerState<R>, Dispatch<ReducerAction<R>>];
type Reserve = {
(from: Date, to: Date, destination: string): Ticket;
(from: Date, destination: string): Ticket
};
const reserve: Reserve = (from: Date, ...args: [toOrDest: Date, destination: string] | [destination: string]): Ticket => {
const isOne = args.length === 1;
return {
type: isOne ? "one-way" : "two-way",
from,
destination: isOne ? args[0] : args[1],
...(isOne ? {} : {to: args[0]})
};
};
Reserve
. Но тогда при наведении мыши на reserve
будет не совсем понятная подсказка (хотя автокомплит вполне корректный).setItems((prev) => {
const i = prev.findIndex(item => item.id === id);
if (i < 0 || prev[i].isClicked) {
return prev;
}
const newArr = [...prev];
newArr[i] = {...prev[i], isClicked: true};
return newArr;
});
function createQueue(onMatch) {
const queue = [];
const checkItem = (item, range, i) => {
if (item[0] <= range[0] && range[1] <= item[1]) {
queue.splice(i, 1);
onMatch(range, item);
return true;
}
return false;
};
const add = (range) => {
for (let i = 0; i < queue.length; ++i) {
if (checkItem(queue[i], range, i) || checkItem(range, queue[i], i)) {
return;
}
}
queue.push(range);
};
return {queue, add};
}
// пример использования
const q = createQueue((a, b) => console.log(a, b));
q.add([2, 4]);
q.add([3, 5]);
q.add([4, 4]); // log ([4, 4], [2, 4])