Skip to content

Type '[] | [undefined]' is not assignable to type '[] | [string]' #28

@Bubblesphere

Description

@Bubblesphere

Hi, I'm getting the following error

Argument of type '() => Generator<string, void, string>' is not assignable to parameter of type '(setCancelHandler: (onCancel?: (() => void) | undefined, onCancelError?: ((err: Error) => void) | undefined) => void) => IterableIterator<any>'.
  Type 'Generator<string, void, string>' is not assignable to type 'IterableIterator<any>'.
    Types of property 'next' are incompatible.
      Type '(...args: [] | [string]) => IteratorResult<string, void>' is not assignable to type '(...args: [] | [undefined]) => IteratorResult<any, any>'.
        Types of parameters 'args' and 'args' are incompatible.
          Type '[] | [undefined]' is not assignable to type '[] | [string]'.
            Type '[undefined]' is not assignable to type '[] | [string]'.
              Type '[undefined]' is not assignable to type '[string]'.
                Type 'undefined' is not assignable to type 'string'.ts(2345)

using

const [a, setA] = useState('');
useAsyncEffect(function*() {
    const value: string = yield "foobars";
    setA(value);
}, []);

which seems to be caused by
result = generator.next(result.value);

because TNext is undefined by default
Iterator<T, TReturn = any, TNext = undefined>

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions