interface Row<T, K extends keyof T> {
field: K;
showValue?: (value: T[K]) => string;
}
interface Data {
name?: string;
age?: number;
}
type AData<T> = {
[K in keyof T]: Row<T, K>;
}[keyof T]
const A: AData<Data>[] = [
{
field: "age",
// Здесь value должен иметь тип number
showValue: (value) => value.toString(),
},
{
field: "name",
// Здесь value должен иметь тип string
showValue: (value) => value.toString(),
},
];
const findWhere = (shelf, book) => {
for (let i = 0; i < shelf.length; i++) {
let flag = true;
for (let [key, value] of Object.entries(book)) {
if (shelf[i][key] !== value) {
flag = false;
break;
}
}
if (flag) {
return shelf[i];
}
}
return null;
};
interface AnimalProps {
name: string;
}
interface PersonProps {
age: number;
}
type ComponentProps =
| ({ type: 'animal'; } & AnimalProps)
| ({ type: 'person'; } & PersonProps)
// or
interface AnimalType extends AnimalProps {
type: 'animal';
}
interface PersonType extends PersonProps {
type: 'person';
}
type ComponentProps2 = AnimalType | PersonType;
n = 2
[0,1,1] => true
[1,1,0] => false
const arr = [
[0,0,0,0],
[1,0,0,0],
[0,1,0,0],
[0,0,0,0],
];
const n = 2;
const inRow = (arr, oneMax) => {
const { length } = arr;
if(oneMax > length) {
return false;
}
const oneCounter = {
'--': 0,
'||': 0,
'\\': {
top: 0,
bot: 0,
},
'//': {
top: 0,
bot: 0,
},
};
const check = (value, counter, key) => {
if(value === 1) {
counter[key]++;
if(counter[key] === oneMax) {
return true;
}
} else {
counter[key] = 0;
}
return false;
}
for(let i = 0; i < length; i++) {
for(let j = 0; j < length; j++) {
if(
check(arr[i][j], oneCounter, '--') ||
check(arr[j][i], oneCounter, '||')
) {
return true;
}
}
oneCounter['--'] = 0;
oneCounter['||'] = 0;
}
const maxDiags = length - n + 1;
const last = length - 1;
for(let i = 0, maxJ = length; i < maxDiags; i++, maxJ--) {
for(let j = 0; j < maxJ; j++) {
if(
check(arr[j][i + j], oneCounter['\\'], 'top') ||
check(arr[i + j][j], oneCounter['\\'], 'bot') ||
check(arr[j][last - (i + j)], oneCounter['//'], 'top') ||
check(arr[i + j][last - j], oneCounter['//'], 'bot')
) {
return true;
}
}
oneCounter['\\'].top = 0;
oneCounter['\\'].bot = 0;
oneCounter['//'].top = 0;
oneCounter['//'].bot = 0;
}
return false;
}
inRow(arr, n)
Что я упустил?
(error: Error, data: null, info: string) => any
null
вместо Error
.function getProductCollection(func: (error: null | Error, data: ProductUnit[] | null, info: string) => any): void;
function getProductCollection(func: (error: Error, data: null, info: string) => any): void { }
const renderEmployees = () => {
const alphEmployees = [...employees]
.sort((a, b) => a.firstName > b.firstName ? 1 : -1)
.reduce((acc, emp) => {
const { firstName: [firstLetter] } = emp;
acc[firstLetter] ??= [];
acc[firstLetter].push(emp);
return acc;
}, {});
let arr_EN = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];
return (
<div className='empoloyees__alf'>
{arr_EN.map(item => <div className='empoloyees__alf-item'>{item} {helper(alphEmployees[item] ?? [])}</div>)}
</div>
)
}
const getValue = (obj, keys) => keys.reduce((acc, key) => acc?.[key], obj);
type IProps = {
data: (({ icon: any; } | { text: string; }) & { id: string | number })[];
};
type IProps = {
data: Data[];
};
type Data = Data.WithIcon | Data.WithText;
namespace Data {
interface Base {
id: string | number;
}
export interface WithIcon extends Base {
icon: any;
}
export interface WithText extends Base {
text: string;
}
}
const d = new Date('2021-11-03T23:24:00.000Z');
d.setMinutes(d.getMinutes() + 1349);