UNPKG

nesity-types

Version:

A set of TypeScript utilities that help you write stricter code.

49 lines 1.61 kB
// eslint-disable-next-line node/no-unpublished-import,import/no-extraneous-dependencies import { expectTypeOf } from 'expect-type'; import { fromEntries } from './fromEntries.js'; // const tuples: const obj1 = fromEntries([ // ^? ['key1', 1], ['key2', 2], ]); expectTypeOf(obj1).toEqualTypeOf(); // const tuples with mixed types: const obj2 = fromEntries([ // ^? ['key1', 1], ['key2string', '2'], ]); expectTypeOf(obj2).toEqualTypeOf(); // mutable array of const tuples cannot guarrantee existence: const obj1FromMutable = fromEntries([ // ^? ['key1', 1], ['key2', 2], ]); expectTypeOf(obj1FromMutable).toEqualTypeOf(); // mutable arrays of mutable tuples cannot guarrantee existence, but can infer generalized type: const obj2FromMutable = fromEntries([ // ^? ['key1', 1], ['key2string', '2'], ]); expectTypeOf(obj2FromMutable).toEqualTypeOf(); // mutable arrays of mixed const and mutable tuples work correctly: const obj2FromMixed = fromEntries([ // ^? ['key1', 1], ['key2string', '2'], ]); expectTypeOf(obj2FromMixed).toEqualTypeOf(); const fromMutable = fromEntries(mutableTuple); expectTypeOf(fromMutable).toEqualTypeOf(); const fromImmutable = fromEntries(immutableTuple); expectTypeOf(fromImmutable).toEqualTypeOf(); const mixed = fromEntries(mixedTuple); expectTypeOf(mixed).toEqualTypeOf(); const withUnionKeys = fromEntries(tupleWithUnionKeys); expectTypeOf(withUnionKeys).toEqualTypeOf(); const fromArray = fromEntries(tupleArray); expectTypeOf(fromArray).toEqualTypeOf(); //# sourceMappingURL=fromEntries.typeTest.js.map