Skip to content

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 <[email protected]>

* 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 <[email protected]>

* update TS to NodeNext

---------

Co-authored-by: Joe Pea <[email protected]>
Co-authored-by: Will Kelly <[email protected]>
Co-authored-by: 狐狸 <[email protected]>
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