Skip to content

Fixed the return type of the Symbol.observable method in the generated .d.ts #1499

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

Merged
merged 2 commits into from
Jan 25, 2023

Conversation

Andarist
Copy link
Contributor

Notice how the return type in the generated .d.ts is currently just any:

export declare function observable<T>(input: Accessor<T>): {
    subscribe(observer: ObservableObserver<T>): {
        unsubscribe(): void;
    };
    [Symbol.observable](): any;
};

You can verify this easily and quickly here: https://unpkg.com/browse/[email protected]/types/reactive/observable.d.ts#L26

It seems that TS can't emit the computed type when it depends on the this outside of the class context and when this refers to an "anonymous type". You can verify this in this TS playground in the ".D.TS" tab. It's a TypeScript issue - I didn't have time to look if it's already reported though, I might do that later.

Note that within the package itself when TS sees the source files the type of this property is correct. It's purely an issue with the declaration emit.

By adding an explicit type declaration for this we enable the correct declaration emit. I confirmed this locally:

export declare function observable<T>(input: Accessor<T>): Observable<T>;

@changeset-bot
Copy link

changeset-bot bot commented Jan 25, 2023

🦋 Changeset detected

Latest commit: 5ac7fea

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
solid-js Patch
test-integration Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@ryansolid
Copy link
Member

Thank you.

@coveralls
Copy link

coveralls commented Jan 25, 2023

Pull Request Test Coverage Report for Build 4006026998

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 88.233%

Totals Coverage Status
Change from base Build 3993280735: 0.0%
Covered Lines: 1292
Relevant Lines: 1389

💛 - Coveralls

@ryansolid ryansolid merged commit d35a1ca into solidjs:main Jan 25, 2023
@Andarist
Copy link
Contributor Author

You are welcome. I created a TS issue for this here: microsoft/TypeScript#52415

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants