Closed younho9 closed 2 years ago
Why are they broken by this change and why would unknown
fix it?
Parameter type of is.integer
is narrowed to number, so is.integer
does not extend Predicate
type.
is.integer
is used in test cases of is.any
which require Predicate
type function, so broken.
Should I just delete these test cases?
https://github.com/sindresorhus/is/blob/main/test/test.ts#L1528 https://github.com/sindresorhus/is/blob/main/test/test.ts#L1553
is.integer()
should still accept unknown
, like all the other value checks. If it's unknown
, I guess the type guard can simply be number
. I don't think we should change the Integer
type for this though.
is.integer()
should still acceptunknown
, like all the other value checks. If it'sunknown
, I guess the type guard can simply benumber
. I don't think we should change theInteger
type for this though.
I agree with your opinion.
Why did you close?
Why did you close?
I think there are some limitation without changing Integer
type.
<T>(value: T): value is Integer<T> => Number.isInteger(value);
// => Type 'T' does not satisfy the constraint 'number'
Can't you use an overload?
Unfortunately, inference from a function will only try the last overload signature.
Is this a TypeScript bug/limitation or intentional behavior? If it's a bug/limitation, we could potentially wait for it to be fixed.
Could we do something like this? (Not working)
Is this a TypeScript bug/limitation or intentional behavior? If it's a bug/limitation, we could potentially wait for it to be fixed.
It seems a design limitation. https://github.com/microsoft/TypeScript/issues/45634#issuecomment-912820467
Could we do something like this? (Not working)
typescriptlang.org/play?#code/KYDwDg9gTgLgBDAnmYcCSA7GwDmwoA8AKsqqNhgCYDOcGArgLYBG+AfHALxwAGAJAG8SKAL4845YFVr8BzAJY55WMXAD8cYagBcdYADd8AbgCwAKHOhIsBKXRZc+APJQAqhgDWGCAHcMxUg5uLQkQCho6JlYodXtsPEItDl0GFmNzcwAzegwAYxh5CAw4eWpMePxiUPDaVOi4AB84HK9fDDYACn0AQwAbemBdIgBKXR7+1FK4xygXd1a-Yg4BcwBIKGAYeihigDko-AA6UvKZrr6B4dMzEQyzSmBc3u6NuFyi6ngGXufmXuB9mkoCkDjEmt9etdzPJMh0Tg4Eh0Id0-gDQcNhnAVmY4LjIj8Uf9AdFzCIgA
In this example, if value type is string or something, signature could be function isInteger<string>(value: string): value is number
which return type doesn't match with input type.
@younho9 Is there any way we can move this forward or should I close?
I couldn't find a way to solve it. I think you'd better close.
typescript@4.1.2
, sinceInteger
type intype-fest
is using template literal typeis.integer
andis.safeInteger
are narrowed to number, becauseInteger
type extends number type.is.evenInteger
,is.oddInteger
, and also test cases inis.any
are broken.Integer
type extends unknown.resolve #147