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

Improve signal setter type for code completion of string literal unions. #2297

Merged
merged 3 commits into from
Sep 24, 2024

Conversation

Huliiiiii
Copy link
Contributor

Summary

Improve signal setter type for code completion of string literal unions.

How did you test this change?

Reorder overload signatures

type setterNew<in out T> = {
    <U extends T>(value: Exclude<U, Function> | ((prev: T) => U)): U;
    <U extends T>(
        ...args: undefined extends T ? [] : [value: (prev: T) => U]
    ): undefined extends T ? undefined : U
    <U extends T>(value: Exclude<U, Function>): U
    <U extends T>(value: (prev: T) => U): U

}

type SetterOld<in out T> = {
  <U extends T>(...args: undefined extends T ? [] : [value: (prev: T) => U]): undefined extends T
    ? undefined
    : U;
  <U extends T>(value: (prev: T) => U): U;
  <U extends T>(value: Exclude<U, Function>): U;
  <U extends T>(value: Exclude<U, Function> | ((prev: T) => U)): U;
};


type strUnion = "foo" | "bar"

const setterNew: setterNew<strUnion> = (x) => x
const setterOld: SetterOld<strUnion> = (x) => x

setterNew() // completion: "foo" | "bar"
setterNew(x => "") // completion: "foo" | "bar"
// We can all get completion
setterOld() // completion: none
setterOld(x => "") // completion: "foo" | "bar"
// We cant get completionon first function

typescript playground

Copy link

changeset-bot bot commented Sep 19, 2024

🦋 Changeset detected

Latest commit: a9770f0

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 ryansolid changed the base branch from main to next September 24, 2024 15:45
@ryansolid ryansolid merged commit 80b0958 into solidjs:next Sep 24, 2024
1 check passed
@ryansolid
Copy link
Member

Thank you

ryansolid added a commit that referenced this pull request Sep 24, 2024
* update dom-expressions to include client-side API placeholders in web/dist/server.js

* update dom-expressions version to temporary one from git for testing

* update lock file

* Add exports to solid-js/store's server build to match the client build, marking the additional export as not supported on the server side

* update dom-expressions

* fix!: Remove browser field from package.json (#2255)

* fix!: Remove browser field from package.json of core packages so that worker export doesn't get mapped back to removeBrowserPackageJson

BREAKING CHANGE: Jest was previously mentioned as the reason that wasn't removed, but Jest now supports package.json modules. That said, some other tooling might still not support esm exports.

* Create rare-birds-train.md

---------

Co-authored-by: Ryan Carniato <ryansolid@gmail.com>

* better handling of exports client/server

* Improve signal setter type for code completion of string literal unions. (#2297)

* fix

* fix test

* Create shy-islands-talk.md

---------

Co-authored-by: Ryan Carniato <ryansolid@gmail.com>

* update TS to NodeNext

---------

Co-authored-by: Joe Pea <joe@trusktr.io>
Co-authored-by: Will Kelly <67284402+wkelly17@users.noreply.github.com>
Co-authored-by: 狐狸 <134658521+Huliiiiii@users.noreply.github.com>
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.

2 participants