Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript does not report an error with the sample #888

Open
Lonli-Lokli opened this issue Apr 15, 2023 · 2 comments
Open

Typescript does not report an error with the sample #888

Lonli-Lokli opened this issue Apr 15, 2023 · 2 comments
Labels
bug Something isn't working typings Typescript public type definitions issues

Comments

@Lonli-Lokli
Copy link

One more case when typescript does not report an error with the sample (link)

import {sample, createEvent, createStore} from "effector";

type AnyObject = {
    name: string;
}
function isDefined<T>(value: T | null | undefined): value is T {
    return  value !== null && value !== undefined;
}

const voidEvent = createEvent();
const stringEvent = createEvent<string>();
const $nullableStore = createStore<AnyObject | null>(null);

sample({
  clock: voidEvent,
  source: $nullableStore,
  filter: isDefined,
  target: stringEvent
});

Originally posted by @Lonli-Lokli in #811 (comment)

@zerobias
Copy link
Member

Functions with generics are tough to generalize in typescript, so it’s very hard for us to make this working properly, but we’ll try

@zerobias zerobias added bug Something isn't working typings Typescript public type definitions issues labels Apr 15, 2023
@sergeysova sergeysova changed the title Typescript does not report an error with the sample ([link](https://tsplay.dev/w2zJ4w)) Typescript does not report an error with the sample Apr 15, 2023
@Lonli-Lokli
Copy link
Author

Lonli-Lokli commented Apr 15, 2023

An example how it's done with RxJS

https://github.com/ReactiveX/rxjs/blob/master/src/internal/operators/filter.ts#L7

export function filter<T, S extends T, A>(predicate: (this: A, value: T, index: number) => value is S, thisArg: A): OperatorFunction<T, S>;
export function filter<T, S extends T>(predicate: (value: T, index: number) => value is S): OperatorFunction<T, S>;
export function filter<T>(predicate: BooleanConstructor): OperatorFunction<T, TruthyTypesOf<T>>;
/** @deprecated Use a closure instead of a `thisArg`. Signatures accepting a `thisArg` will be removed in v8. */
export function filter<T, A>(predicate: (this: A, value: T, index: number) => boolean, thisArg: A): MonoTypeOperatorFunction<T>;
export function filter<T>(predicate: (value: T, index: number) => boolean): MonoTypeOperatorFunction<T>;
export function filter<T>(predicate: (value: T, index: number) => boolean, thisArg?: any): MonoTypeOperatorFunction<T> {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working typings Typescript public type definitions issues
Projects
None yet
Development

No branches or pull requests

2 participants