function preparedData<T extends Record<string, {name: string, id: string}[]>>(data: T) {
return Object.keys(data).map((key) => {
return data[key as keyof T].map((a) => ({
val: a.name,
newId: a.id,
}));
});
}
class Delegate<Target, Args extends any[], Ret> {
constructor(
private target: Target,
private method: (this: Target, ...args: Args) => Ret,
) {}
public invoke(...args: Args): Ret {
return this.method.apply(this.target, args);
}
}
Вот только конструировать такой делегат в отличии от шарпа придется явно.Argument of type 'ComputedRef' is not assignable to parameter of type 'string'.
Аргумент типа 'ComputedRef' не может быть присвоен параметру типа 'string'.
const pErrorMinMessage = computed<string>(() => {
return 'world'
})
const fun1 = function (val: string) {
console.log('hello' + val)
}
fun1(pErrorMinMessage.value)
type AlbumType = {
id: number;
title: string;
};
enum ActionPoints {
SET_ALBUMS = "SET_ALBUMS",
ADD_ALBUM = "ADD_ALBUM",
REMOVE_ALBUM = "REMOVE_ALBUM"
}
type ActionType = {
type: ActionPoints.SET_ALBUMS;
payload: AlbumType[];
} | {
type: ActionPoints.ADD_ALBUM;
payload: AlbumType;
} | {
type: ActionPoints.REMOVE_ALBUM;
payload: number;
};
const reducer = (state: AlbumType[], action: ActionType) => {
switch (action.type) {
case ActionPoints.SET_ALBUMS:
return action.payload;
case ActionPoints.ADD_ALBUM:
return [...state, action.payload];
case ActionPoints.REMOVE_ALBUM:
return state.filter((album) => album.id !== action.payload);
default:
return state;
}
};
declare const JSON: {
id: number;
}[];
export default JSON;