Conversation
|
Should it maybe be called |
source/internal/type.d.ts
Outdated
| /* | ||
| Indicates the value of `exactOptionalPropertyTypes` compiler option. | ||
| */ | ||
| type ExactOptionalPropertyTypesEnabled = [(string | undefined)?] extends [string?] |
There was a problem hiding this comment.
| type ExactOptionalPropertyTypesEnabled = [(string | undefined)?] extends [string?] | |
| export type ExactOptionalPropertyTypesEnabled = [(string | undefined)?] extends [string?] |
I wonder why TS doesn't warn about this, even with ESM...
There was a problem hiding this comment.
I wonder why TS doesn't warn about this, even with ESM...
Umm... not sure why, maybe it's treating the module as "ambient".
test-d/every.ts
Outdated
| expectType<NonStrictNeverEvery<[never, any, never, any], never>>({} as boolean); | ||
|
|
||
| expectType<Every<any, never>>(false); | ||
| expectType<Every<never, any>>(false); |
There was a problem hiding this comment.
Maybe also:
expectType<Every<unknown[], number>>({} as boolean);
expectType<Every<unknown[], any>>(true);
expectType<Every<[never, 1], any>>(true);
expectType<Every<[1, never], any>>(true);
expectType<Every<[never, ...never[], never], any>>(true);There was a problem hiding this comment.
@sindresorhus Shouldn't Every<unknown[], number> return false and not boolean, because unknown extends number is not true.
type T = unknown extends number ? 'Y' : 'N';
//=> 'Y'Every<any[], number> returns boolean because any distributes over conditionals.
type T = any extends number ? 'Y' : 'N';
//=> 'Y' | 'N'
I chose the name Updated it to |
a609966 to
f931b95
Compare
| export type IsExactOptionalPropertyTypesEnabled = [(string | undefined)?] extends [string?] | ||
| ? false | ||
| : true; |
There was a problem hiding this comment.
Credits to @Emiyaaaaa for suggesting this type ✨
|
|
||
| expectType<Not<true>>(false); | ||
| expectType<Not<false>>(true); | ||
| // FIXME |
There was a problem hiding this comment.
There's nothing to fix here, Not<boolean> should return boolean.
This PR fixes all the known limitations of the internal
Everytype and makes it publicly available.type-fest/source/internal/array.d.ts
Line 103 in a891143
Introduced a new
CollapseRestElementtype to handle arrays with rest and optional elements. This utility replaces the rest element with a single element that has the same type as the rest element. For example,CollapseRestElement<[string, ...number[], boolean]>returns[string, number, boolean].Before
Everyperforms its computation, the input array is simplified usingCollapseRestElement. This simplification shouldn't alter the result ofEverybecause the expected output for[number, …string[], boolean]and[number, string, boolean]is the same.