ЕЛ
Size: a a a
ЕЛ
fe
implements
проверяет только тип инстанса, то есть свойства инстанса ("поля класса") и прототипа; а конструктор и статические свойства — это отдельный тип самого класса.Б
class Queue<t> { private data = []; push = (item: T) => this.data.push(item); pop = (): T => this.data.shift(); }
N
class Queue<t> { private data = []; push = (item: T) => this.data.push(item); pop = (): T => this.data.shift(); }
C☭
AY
SM
type Filter = {
name?: {
equalTo?: string,
includes?: string,
}
}
type Foo = { [key in keyof Filter]: keyof Required<Filter>[key] };
const filterMapOk0: Foo = {
name: 'equalTo',
};
const filterMapOk1: Foo = {
name: 'includes',
};
const filterMapOk2: Foo = {
name: undefined,
};
const filterMapError: Foo = {
name: 'equalTo1',
};
AY
type Filter = {
name?: {
equalTo?: string,
includes?: string,
}
}
type Foo = { [key in keyof Filter]: keyof Required<Filter>[key] };
const filterMapOk0: Foo = {
name: 'equalTo',
};
const filterMapOk1: Foo = {
name: 'includes',
};
const filterMapOk2: Foo = {
name: undefined,
};
const filterMapError: Foo = {
name: 'equalTo1',
};
SM
SM
const countsHooksFactory = <T extends Function>(
useCounts: T,
mapper: ReturnType<T> /* There is an error */
): TUseCounts => isVisible => {
const {
filters,
searchControl,
subGeoFilters,
urlParameter
} = usePrepareValuesForCountsRequest();
const { data, loading } = useCounts({
skip: !isVisible,
variables: {
searchControl,
filters,
subGeoFilters,
urlParameter
}
});
return {
counts: mapper(data),
loading
};
};
// Example of usage:
const useTripAdvisorRatingCounts = countsHooksFactory(useGetSrlTripadvisorRatingsFilterCountsQuery,
(data: /* I expect that this type will be infered*/) => data?.srl.mainFilter.taRating);
AY
SM
Type 'T' does not satisfy the constraint '(...args: any) => any'.
Type 'Function' is not assignable to type '(...args: any) => any'.
Type 'Function' provides no match for the signature '(...args: any): any'.
SM
const countsHooksFactory = <
T extends (...args: any) => { data: unknown; loading: boolean }
>(
useCounts: T
) => (
mapper: (val: ReturnType<T>['data']) => IFilterCount | IFilterCount[]
): TUseCounts => isVisible => {
const {
filters,
searchControl,
subGeoFilters,
urlParameter
} = usePrepareValuesForCountsRequest();
const { data, loading } = useCounts({
skip: !isVisible,
variables: {
searchControl,
filters,
subGeoFilters,
urlParameter
}
});
return {
counts: mapper(data),
loading
};
};
const useTripAdvisorRatingCounts = countsHooksFactory(
useGetSrlTripadvisorRatingsFilterCountsQuery
)(data => mapFilterToCountsMapper(data?.srl.mainFilter.taRating));
˸A
АЗ
UT
const foo = (): never => {
while (true) {
// ... Some code
}
};
nst bar = (): never => {void альтернатива (алиас) для undefined
throw new Error('Not implemented yet');
}
А
˸A
UT
˸A