-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
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
fix(types): fix function prop type inference #11223
base: dev
Are you sure you want to change the base?
Conversation
@ktsn this might be up your alley! |
@@ -154,6 +154,45 @@ const FunctionalScopedSlotsComponent = Vue.extend({ | |||
} | |||
}); | |||
|
|||
declare function assertBoolean<A>(value: string extends A ? never : (A extends boolean ? A : never)): true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To explain a little: calling assertBoolean(value)
will only compile if value
is precisely boolean
, and not if value
is boolean | AnotherType
, nor if value
is any
(the latter is why ...lue: string extends A ? nev...
is there—it's just a way to throw if value
is any
).
this.functionProp(); // callable (good) | ||
assertBoolean(this.functionPropWithBooleanReturnType()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For reference...
Before the change, these lines were failing with:
this.functionProp();
(property)
functionProp
:boolean | Function
This expression is not callable.
No constituent of type 'boolean | Function
' is callable. ts(2349)
assertBoolean(this.functionPropWithBooleanReturnType());
(property)
functionPropWithBooleanReturnType
:boolean | (() => boolean)
This expression is not callable.
Not all constituents of type 'boolean | (() => boolean)
' are callable.
Type 'false
' has no call signatures. ts(2349)
Also related: microsoft/TypeScript#17574 and #9873 |
Note: If it helps with confidence, I've tested that this change works & compiles in a project with 154 different |
I've been looking for a solution for some time now, thanks! |
Can anyone look at this? I'd really appreciate it! |
Hi, is there any update on this? I'd be happy this PR was merged. |
Can someone look at this? It's been a thorn in our side for a long time. |
@ktsn ? |
close #9357
What kind of change does this PR introduce? (check at least one)
Does this PR introduce a breaking change? (check one)
If yes, please describe the impact and migration path for existing applications:
The PR fulfills these requirements:
dev
branch for v2.x (or to a previous version branch), not themaster
branchfix #xxx[,#xxx]
, where "xxx" is the issue number)If adding a new feature, the PR's description includes:
Other information:
Before this change:
After this change: