Summary
This is a huge release! 120 new types. All open issues resolved. A huge number of performance and correctness fixes.
Breaking
- Require TypeScript 6 9ec2593
- Require Node.js 22 9ec2593
- Require
exactOptionalPropertyTypes: truein your tsconfig 82f2b44- The types no longer have compatibility logic for
exactOptionalPropertyTypes: false. Disabling it is unsupported.
- The types no longer have compatibility logic for
- Reminder:
type-festrequiresstrict, which is the default since TypeScript 6. Do not set it tofalse. - Remove the deprecated
IfAny,IfNever,IfUnknown,IfNull, andIfEmptyObjecttypes. UseIfwith the matchingIs*type. 6fc1861 - Remove the deprecated
ReadonlyTupletype. UseReadonly<TupleOf<Length, Element>>. 6fc1861 CamelCase,PascalCase,KebabCase,SnakeCase,ScreamingSnakeCase,DelimiterCase,Words, and their*CasedProperties/*CasedPropertiesDeeptypes: EnablesplitOnPunctuationby default. ebc42e5KebabCase<'div.card::after'>is now'div-card-after'(was'div.card::after').- A leading
$is now removed:CamelCase<'$foo'>is'foo'.
CamelCase/PascalCase(and their*CasedPropertiestypes): DisablesplitOnNumbersby default 976bd26CamelCase<'p2p_network'>is now'p2pNetwork'(was'p2PNetwork'). The other case types already usedfalse.
CamelCase/PascalCase(and their*CasedPropertiestypes): EnablepreserveLeadingUnderscoresby default 8144ba1CamelCase<'_id'>is now'_id'(was'id'). This matches thecamelcasepackage.PascalCase<'_foo_bar'>is now'_FooBar'(was'FooBar').
Words: WithsplitOnPunctuation: false, punctuation now stays inside the word:Words<'hello:world', {splitOnPunctuation: false}>is['hello:world'](was['hello', ':world']) 9f2ad66PartialDeep: EnablerecurseIntoArraysby default. ab0e23d- The elements of arrays and tuples are now deeply partial, and the fixed elements of tuples become optional.
allowUndefinedInNonTupleArrays: truenow works alone. Before, it also neededrecurseIntoArrays: true.
PartialOnUndefinedDeep: EnablerecurseIntoArraysby default 939abe3ExtendsStrict: EnablestrictAnyby default, soExtendsStrict<any, number>is nowfalse. Pass{strictAny: false}to get the old behavior. b2f7ed4Split: Rename thestrictLiteralChecksoption tostrictbc38ddbStringToArray: Replace themapNonLiteralsDirectlyoption withstrict, which has the opposite meaning.{mapNonLiteralsDirectly: true}is now{strict: false}. b61e528- The old option names now give a compiler error.
ReadonlyDeep: ConvertDateto the newReadonlyDatetype, which has noset*methods.WritableDeepconverts it back toDate. c533251TsConfigJson: Remove the options and values that TypeScript 5.5 removed and that TypeScript 6.0 deprecated. 393c093 0716fa8 4e54420 65b2db8- Predicates now return
falseinstead ofneverwhen an input isnever9ec1de5- This applies to
IsEmptyObject,IsFloat,IsInteger,IsNegative,GreaterThan,GreaterThanOrEqual,LessThan,LessThanOrEqual,Includes,IsOptionalKeyOf,IsRequiredKeyOf,IsReadonlyKeyOf, andIsWritableKeyOf. - If you checked the result with
IsNeveror[Result] extends [never], check forfalseinstead.
- This applies to
IsNull/IsUndefined: Returnfalseforanyandnever(wastrue) 349271e 750177a 65fc2ebIsOptionalKeyOf/IsRequiredKeyOf/IsReadonlyKeyOf/IsWritableKeyOf: Read a literal key of an index signature like the index signature, and read ananyobject likeRecord<PropertyKey, any>62df5d9 5a2e786IsOptionalKeyOf<Record<string, number>, 'x'>is nowtrue(wasfalse), andIsRequiredKeyOfis nowfalse.IsReadonlyKeyOf<{readonly [key: string]: number}, 'x'>is nowtrue(wasfalse).- With an
anyobject, the result wasnever. Now a literal key is optional and writable, soIsOptionalKeyOf<any, 'a'>andIsWritableKeyOf<any, 'a'>aretrue, andIsRequiredKeyOf<any, 'a'>andIsReadonlyKeyOf<any, 'a'>arefalse. Astring,number, orsymbolkey is required, and ananykey givesboolean.
FixedLengthArray: Returnneverfor a non-literal length, likenumber. Use a normal array type for an unknown length. 88281feFinite/NonNegative: Returnneverfor the widenumbertype (wasnumber) 23e295fNonNegative/Negative: RejectInfinityand-Infinity(for example1e999) 608026dJsonifiable: Reject values typedobject, because they can contain anything 92aba94ConditionalPickDeep: Matchanyandnevervalues likeConditionalKeys. Anevervalue is no longer picked, and ananyvalue is now picked. 02aef94- Other result changes that you can see in existing code:
Simplify: Keep functions, class constructors, and branded primitives as is.Simplify<() => void>was{}. 28b9f8e 7d0a323Merge: Keep the call signatures of the input 166b209- The deep types (
PartialDeep,ReadonlyDeep,RequiredDeep, and others) no longer recurse into DOM nodes, likeHTMLElemente379753 Entries/Entry: Pair each key with its own value.Entry<{a: 1; b: 'x'}>is now['a', 1] | ['b', 'x'](was['a' | 'b', 1 | 'x']). 34d036fValueOf: Read the values of every union member.ValueOf<{a: 1} | {b: 2}>is now1 | 2(wasnever). 6a0de70 1a2e90aGet: Returnundefinedfor the union members that do not have the key.Get<{a: 1} | {b: 2}, 'a'>is now1 | undefined(wasunknown). cc955bdLiteralToPrimitiveDeep: Keep tuples as tuples.[1]becomes[number](wasnumber[]). 8173c2cLiteralToPrimitive: Returnanyforany65fc2ebMultidimensionalArray/MultidimensionalReadonlyArray: Allow leaf values at all levels when the dimension is not known 762b656RemovePrefix/RemoveSuffix: Returnstringwhen a non-literal input cannot contain the affix.RemovePrefix<`user_${string}`, 'admin_'>is nowstring(was`user_${string}`). b8c6ef2 1fbd1d2IsEmptyObject: Returnfalseforobject(wastrue) and forany(wasboolean) 43c237d 9ec1de5HasRequiredKeys: Returnfalsefor index signatures, arrays without required elements, andany(wastrue) 1c184e6IsFloat: Returnbooleanforany(wasfalse) cdf0edeAsyncify: Keep the return type of each function in a union 1b374deSingleKeyObject: Returnneverforboolean(wasboolean), and return broad object types, likeobjectandRecord<string, number>, as is (wasnever) 2745e8f 43c237dStringToArray: A non-literal part givesstringelements, because each character does not always match the type of the whole part.StringToArray<Lowercase<string>>is nowstring[](wasLowercase<string>[]). b9337f2
OpaqueandUnwrapOpaqueare still deprecated, and v7 will remove them. UseTaggedandUnwrapTagged. 62c465e
New types
AnyAsyncFunction: Matches any asynchronous function. 32c73cdAnyFunction: Matches any function. 32c73cdApplyDefaultOptions: Apply default options to specified options, preserving literal types. b22217aArrayAt: Get the type of the element at the given index of an array, likeArray#at(). f00afbbArrayChunk: Split an array into consecutive chunks of the given size. b68f6cfArrayFlat: Flatten an array type to the given depth, likeArray#flat(). d4b8be9ArrayGroupBy: Group an array of objects by a property, preserving the order within each group. b68f6cfArrayToRecord: Transforms an array of objects into a record keyed by one of their properties. beb7d8aArrayTrim: Remove the elements of the given type from both ends of an array. 219ea42ArrayTrimEnd: Remove the elements of the given type from the end of an array. 219ea42ArrayTrimStart: Remove the elements of the given type from the start of an array. 219ea42ArrayUnique: Remove duplicate element types from an array, preserving their first occurrence. b68f6cfArrayZip: Pair the elements at matching positions in two arrays. b68f6cfAsciiPunctuationCharacter: Matches a single ASCII punctuation character. fbecabaAsExtendable: Allow any object type to be used in theextendsclause of an interface or theimplementsclause of a class, which otherwise only accept a type name. 9b93e09AsyncFunction: Matches an asynchronous function. 32c73cdCamelCaseString: Astringthat is in camel case, like'fooBar'. 70e7c1aCollapseLiterals: Collapse literal union members into broader types already present in the union. ef86da2ConsistsOnlyOf: Returns a boolean for whether a string consists only of zero or more repetitions of the given pattern. d941796Curry: Convert a function into a chain of functions that each accept one argument. b68f6cfDefaultsFor: Create the type of a defaults object for the given options type, with only its optional keys, made required. 6d3571cEmptyArray: Represents a strictly empty readonly array, implemented as the readonly empty tuplereadonly []. 15416b2ExcludeValues: Exclude the given type from the value of every property in an object type, or every element in an array type. 8b6905cExtractLiterals: Extract the literal types from a union, removing wide types likestringand infinite string types like`on${string}`. 29ab96dExtractValues: Extract the given type from the value of every property in an object type, or every element in an array type. 4fbae20Falsy: Matches any falsy value. 27f2429FirstArrayElement: Extract the type of the first element of an array. 8d73897Flavor: Attach a name to a type without requiring a cast, so that differently named types cannot be mixed. adf9875FromEntries: Create an object type from an array of key-value pairs. b68f6cfFunctionParameters: Extract the parameters of a function type as a tuple. c437399GuardedType: Extract the type that a type predicate function narrows its parameter to. 65955f9HasMultipleCallSignatures: Returns a boolean for whether the given function type has multiple distinct call signatures. 9402832IncompatibleKeys: Get the keys that both types have, where the property inSourceis not assignable to the property inTarget. d5d96f6IndexOf: Returns the union of indices at which the given item can be found in the given array. 2fbae25IndexTuple: Create a tuple type of the indices of a constant array or tuple. 0e170c9InvertRecord: Create a record that maps each property value to its original keys. b68f6cfIsMutuallyAssignable: Returns a boolean for whether the two given types are mutually assignable. abb2df2IsNumberLike: Returns a boolean for whether the given type is anumberor a numeric string. 8f1cc35IsNumericString: Returns a boolean for whether the given type is a numeric string without surrounding whitespace. 48d6a5fIsPrimitive: Returns a boolean for whether the given type is a primitive. b54cc19IsReadonlyArray: Returns a boolean for whether the given array or tuple is readonly. 99268d9IsRecordLike: Returns a boolean for whether the given type is a record-like object. 2c97a9bIsTemplateLiteral: Returns a boolean for whether the given type is a template literal type: astringtype with infinitely many possible values, other than plainstring. 47ef070IsUnionMember: Returns a boolean for whether the given union type includes the given member. f892fd8IsWhitespace: Returns a boolean for whether a string is non-empty and consists only of whitespace characters. be1b5d8JoinUnion: Join a union of strings and/or numbers using the given string as a delimiter. 6a1e840JsonifiableArray: Matches an array that can be losslessly converted to JSON. 619b7baJsonifiableObject: Matches an object that can be losslessly converted to JSON. 619b7baJsonifiableValue: Validates that a function argument of typeValuecan be losslessly converted to JSON, including aninterface. 97fe10aJsonPointer: Generate a union of all possible JSON Pointer strings for the given type. e3f4efbKebabCaseString: Astringthat is in kebab case, like'foo-bar'. 70e7c1aLiteralList: Enforces that a tuple contains exactly the members of a union type, with no duplicates or omissions. 6a1e840MapKey: Get the key type of aMap,ReadonlyMap, orWeakMap. 1ff1dc1MapValue: Get the value type of aMap,ReadonlyMap, orWeakMap. 1ff1dc1MatchingKey: Resolve a property key to the matching key type in an object, converting between numeric and string forms when needed. a23883fMergeAll: Merge any number of types into a new type. Keys of each type override keys of the types before it. b550b41MinimumLengthArray: Create an array type with at least the given number of elements of the given type. 8303a6eModify: Create a type from an object type and a modifier type, where keys of the modifier type override keys of the object type, and keys with thenevertype are removed from the result. 6981c50ModifyDeep: Recursively create a type from an object type and a modifier type, where keys of the modifier type override keys of the object type, and keys with thenevertype are removed from the result. 6981c50Negate: Returns the specified number with its sign reversed. 5b1c348NonNegativeIntegerString: Astringthat represents a non-negative integer, like'42'. df2fb32Not: Returns a boolean for whether the given type isfalse. c3328b0ObjectEntries: Create a type that describes the key-value pairs produced byObject.entries, even for a generic object type. cf1f757ObjectEntry: Create a type that describes a single key-value pair produced byObject.entries, even for a generic object type. cf1f757ObjectToTuple: Convert an object with consecutive numeric keys starting at zero into a tuple. c53a825ObjectToUnion: Create a union of single-property objects, one for each property of the given object. 7f522f9OptionalPaths: Get a union of all paths to optional properties in the given object. a1c5705OverloadParameters: Extract the parameter types of all overloads as a union. 2508f3cOverloadReturnType: Extract the return types of all overloads as a union. 2508f3cOverloads: Extract all overload signatures of the given function type as a tuple, preserving declaration order. 2508f3cOverridePropertiesDeep: Override existing properties of the given type deeply. Similar toMergeDeep, but requires overridden keys to exist at every level. c96c9efParsePath: Convert a property path into a tuple of keys, with numeric indices. 03f5566PartialApply: Create the type of a function with the given leading arguments already applied. d232733PartialOnUndefined: Create a type where all keys acceptingundefinedtype are set to optional. 9ad0fb4PascalCaseString: Astringthat is in pascal case, like'FooBar'. 70e7c1aPickNonNever: Pick only the properties of the given object type that do not have thenevertype. a15cfd8PickReadonly: Pick only thereadonlyproperties from the given object type, leaving out the writable ones. 892423aPickWritable: Pick only the writable properties from the given object type, leaving out thereadonlyones. 892423aPipe: Create the signature of a function pipeline, checking that adjacent stages are compatible. b68f6cfPropertyValue: Get the type of a property, orneverif the key does not exist. 37d6f0eReadonlyDate: Matches aDatethat cannot be changed. 9c943a5RequireArity: Require a function to have at least the given number of required parameters. 50b0027RequiredKeepUndefined: Create a type that makes all keys required, while the keys that were optional also acceptundefined. 55dede9RequiredNonNullable: Create a type that makes all keys required and non-nullable, including the elements of an array or tuple. be3f010RequireNone: Create an object type that forbids the given keys, to intersect with another object type. 5b12320RouteParameters: Extract the named parameters from a URL route pattern, like/users/:id. e529994ScreamingSnakeCasedProperties: Convert top-level object properties to screaming snake case. 2e1d2cdScreamingSnakeCasedPropertiesDeep: Convert object properties to screaming snake case recursively. 2e1d2cdScreamingSnakeCaseString: Astringthat is in screaming snake case, like'FOO_BAR'. 70e7c1aSetNullable: Create a type that makes the given keys nullable, while keeping the remaining keys as is. f227ed8SetOptionalDeep: Create a type that makes the given keys optional, with support for deeply nested key paths, while keeping the remaining keys as is. 2398c41SetOptionalExcept: Create a type that makes all keys optional except the given keys, which are kept as is. 0cf968cSetProperty: Set a deeply-nested property on an object using a key path, like Lodash's.set()function. b2f526bSetRequiredExcept: Create a type that makes all keys required except the given keys, which are kept as is. 0cf968cSetRequiredNonNullable: Create a type that makes the given keys required and non-nullable, while keeping the remaining keys as is. 419959bSimplifyUnion: Flattens a union type to improve type hints shown in editors, by showing the members instead of the type alias names. 86ea62cSnakeCaseString: Astringthat is in snake case, like'foo_bar'. 70e7c1aStartsWith: Returns a boolean for whether the given string starts with the given prefix. 0cbb6e8StrictEventTarget: A stricter version ofEventTargetthat maps event names to event types. 52914ecStringReverse: Reverse the order of characters in a string literal type. e074cc4StringToBoolean: Converts a boolean string to a boolean literal. 5fde933SubsetOf: Constrain a type to be a subset of another type, returning it as is. c2b0d50SubstituteDeep: Recursively replaces every occurrence of a type in another type. c3e825fThunkable: Create a type that represents either the value or a function that returns the value. cc3e31fToString: Convert a primitive type to its string representation. a9d0e86Truthy: Remove the falsy types from the given type, likeif (value)does. 27f2429TupleLength: Return the length of a tuple. 3fb7450TupleMax: Returns the maximum number in a tuple of numbers. 88dfc59TupleMin: Returns the minimum number in a tuple of numbers. 88dfc59TupleToEnum: Create an enum-like object type from a tuple of property keys, where each key maps to itself, or to its index with thenumericoption. 87d8020Uncurry: Convert a chain of functions into a function that accepts all arguments at once. d2ba210UndefinableDeep: Create a deep version of another type where leaf values also acceptundefined, keeping object containers present. 1d47047UndefinedOnPartial: Create a type where all optional keys are set to also acceptundefined. 9ad0fb4UndefinedToOptional: Make properties with a union containingundefinedoptional, removingundefinedfrom their values. 8263679UnionMin: Returns the minimum number in a union of numbers. c3099e0UnionToEnum: Create an enum-like object type from a union of property keys, where each key maps to itself. 87d8020UnknownCollection: Matches an array, map, or set, including readonly and weak variants. 3ab86faUnwrapBrandedPrimitive: Remove brand properties from primitive types while preserving literal types. 78a1fd9ValueOfDeep: Create a union of all leaf values in the given object, including values in nested objects and arrays. c708f0bWhitespaceCharacter: Matches a single whitespace character. d2bcd21
Improvements
PartialDeep,ReadonlyDeep,RequiredDeep,WritableDeep,NonNullableDeep: Add akeepoption to leave the matching types as is c09e9ecConditionalKeys,ConditionalPick,ConditionalExcept: Add astrictoption, so the whole union value must match the condition 1f61c5dPaths: Add thevalueType,recurseIntoArrays,requiredOnly, andmaxCircularDepthoptions 2c5d371 4cbbaca e17546cConditionalPickDeep: Recurse into optional object properties 6e9ce0bGreaterThan,GreaterThanOrEqual,LessThan,LessThanOrEqual: Supportbigintd2fec83TypedArray: Add aBuffertype parameter 733ccc5Get: Accept numbers in paths, non-literal number indexes on arrays and tuples, andPaths<T>for a genericTd02234b 801fa7f 1c3ff80 edbbd28PickDeep,SetRequiredDeep,SetNonNullableDeep: Accept paths deeper thanPathslists f339d83 dac3375SetOptional,SetRequired,SetReadonly,SetNonNullable,SetFieldType,Except,RequireAtLeastOne,RequireExactlyOne,RequireOneOrNone,RequireAllOrNone,ValueOf: Accept keys of any union member 6f4eaa7 3c49f2a b4fd7ce 1a2e90aDistributedOmit: Accept keys that are not in the type c4f0f20Class,Constructor,AbstractClass,AbstractConstructor: Accept readonly argument tuples cbc9e15IntRange,IntClosedRange: Support enum and non-literal bounds 7a9c7e8SharedUnionFieldsDeep,SimplifyDeep,ConditionalSimplifyDeep,Schema,RequiredDeep,NonNullableDeep: Support recursive array element types e2575dc 0d4ce83 41b3eaa 3c27bdd 0b7a150StructuredCloneable: Accept readonly dates, shared array buffers, andBigIntwrapper objects 7fd58f4 e5fc826 38f3730PackageJson: Addgypfileandlibc, and accept arrayfunding, nestedexportsandimportsfallback arrays, and required peer dependency metadata 65b2db8 df9f758 e69ce64TsConfigJson: Add theES2016.Intl,ESNext.Date,ESNext.SharedMemory, andESNext.TypedArrayslib values, and changegenerateTraceto a directory string 65b2db8- Many numeric and string types accept branded primitives and enum members, for example
Sum,Subtract,GreaterThan,ArraySlice,ArraySplice,TupleOf,Split,Replace,Trim,Join, andStringRepeatd13a397 43e8c5c ddb0c2b 930c7b9 a65f404 cc4c6da ce79ec7 ad8f97e 7ddfc14 7e8cb22 2a42f6f - Improve type-checking performance, especially for
Get,PickDeep,OmitDeep, and theSet*Deeptypes with large object types f5666bc 8a15ef4 307c128
Fixes
Jsonify: Omit properties based on theirtoJSON()result, keep the length and holes of optional tuples, keep the elements of tagged tuples, keep literal keys next to an index signature, and fix infinite recursion withJsonValueb0975a1 02adfbc c057ca6 7237dd9 c1c084f 666a414Exact: Fix union inputs, index signatures with object values, and nested objects under optional or nullable properties 63c8a22 150166b c89866bPickDeep: Keep union members that the path cannot go into, and merge several paths into the same tuple 2c7c89b a597928OmitDeep: Keep a tuple or array unchanged for an out-of-bounds, negative, or noncanonical index e3ef5b7 237f41cConditionalKeys: Keep declared keys when the object has an index signature 6328ee0ConditionalPick,ConditionalExcept,OmitDeep,SharedUnionFields,AllUnionFields,ExclusifyUnion,RequireAllOrNone,RequireExactlyOne,RequireOneOrNone: Keep declared fields next to an index signature 8818aae 873cd42 0a4d9a3 96ecce9 0f022d2 3934944Merge,Spread,MergeDeep: Fix tuples, optional tuple positions, readonly properties, symbols, and numeric index signatures 2fabdf5MergeExclusive: Fix union members facd526Replace: Fix non-literal search strings 37a2727Join: Fix empty rest elements, and keep a union delimiter the same in the whole result e7b9c10 d7e5caeKeysOfUnion: Accept keys narrowed withkeyofon generic types baf01caIsLiteral: Fix an unresolved result for template literal types intersected with{}c73a956IsLiteral,IsNumericLiteral,IsStringLiteral: Fix wrapped results in generic code 691aac6ArraySlice,ArraySplice,ArrayIndices,ExcludeRestElement,SplitOnRestElement,TupleOf: Fix optional elements, readonly arrays, negative indices, and unknown lengths 7c8f174GreaterThan,LessThan,Sum,Subtract,Absolute,IntRange,IsFloat,IsInteger: Fix decimal fractions, branded numbers, and enum members cdf0ede- Case conversion types: Fix non-literal, branded, Unicode, and mixed union inputs 9f2ad66 50e46c1
- Deep types: Keep tuples, functions, receivers, and built-in types 8173c2c
SetParameterType,SetReturnType,Asyncify: Keepthisparameters and readonly rest parameters 65fc2eb f8d43f2UnwrapTagged: Remove all tags from a type with several tags 65fc2eb cbb9188TaggedUnion: Leave missing dictionary entries out of the result afc29e0FindGlobalType: Keep the found globals when other names are missing 1750664ExcludeStrict: Allow exclusions from overlapping union members 777f4e9Writable: Fix numeric enum keys, and keep readonly containers when no keys are selected 92d0c07 db9af8a- Many object types: Match numeric keys and their string forms (
0and'0'), and string enum keys, consistently a99e994 0adbfbb 9ec5640 f5b6178
Migration guide
TypeScript and tsconfig
Upgrade to TypeScript 6 or later, and enable exactOptionalPropertyTypes in your tsconfig. strict does not enable it.
{
"compilerOptions": {
"exactOptionalPropertyTypes": true
}
}strict is the default since TypeScript 6, so you can remove "strict": true. Do not set it to false.
Removed If* types
Use If with the matching Is* type. If has no default branches, so give both.
-import type {IfAny} from 'type-fest';
+import type {If, IsAny} from 'type-fest';
-type Result = IfAny<T, 'any', 'not any'>;
+type Result = If<IsAny<T>, 'any', 'not any'>;| Removed | Replacement |
|---|---|
IfAny<T, A, B>
| If<IsAny<T>, A, B>
|
IfNever<T, A, B>
| If<IsNever<T>, A, B>
|
IfUnknown<T, A, B>
| If<IsUnknown<T>, A, B>
|
IfNull<T, A, B>
| If<IsNull<T>, A, B>
|
IfEmptyObject<T, A, B>
| If<IsEmptyObject<T>, A, B>
|
If you used the default true and false branches, like IfAny<T>, use the Is* type directly: IsAny<T>.
Note: IsNull<any> is now false. IfNull<any> returned the first branch.
ReadonlyTuple
-import type {ReadonlyTuple} from 'type-fest';
+import type {TupleOf} from 'type-fest';
-type FencingTeam = ReadonlyTuple<string, 3>;
+type FencingTeam = Readonly<TupleOf<3, string>>;
//=> readonly [string, string, string]Note: The order of the type arguments is different.
Case conversion defaults
The case conversion types now split on punctuation by default. CamelCase and PascalCase also keep leading underscores, and do not split on numbers.
import type {CamelCase, KebabCase} from 'type-fest';
type A = CamelCase<'foo-bar:baz'>;
//=> v5: 'fooBar:baz'
//=> v6: 'fooBarBaz'
type B = CamelCase<'_id'>;
//=> v5: 'id'
//=> v6: '_id'
type C = CamelCase<'p2p_network'>;
//=> v5: 'p2PNetwork'
//=> v6: 'p2pNetwork'
type D = KebabCase<'div.card::after'>;
//=> v5: 'div.card::after'
//=> v6: 'div-card-after'To get the v5 results, give the old defaults as options:
import type {CamelCase, CamelCasedProperties, KebabCase} from 'type-fest';
type OldCamelCaseOptions = {
splitOnPunctuation: false;
splitOnNumbers: true;
preserveLeadingUnderscores: false;
};
type A = CamelCase<'foo-bar:baz', OldCamelCaseOptions>;
//=> 'fooBar:baz'
type B = CamelCasedProperties<{_id: string}, OldCamelCaseOptions>;
//=> {id: string}
type C = KebabCase<'div.card::after', {splitOnPunctuation: false}>;
//=> 'div.card::after'recurseIntoArrays
PartialDeep and PartialOnUndefinedDeep now also change the elements of arrays and tuples.
import type {PartialDeep} from 'type-fest';
type Settings = {
layers: Array<{name: string}>;
position: [x: number, y: number];
};
type A = PartialDeep<Settings>;
//=> v5: {layers?: Array<{name: string}>; position?: [x: number, y: number]}
//=> v6: {layers?: Array<{name?: string}>; position?: [x?: number, y?: number]}To keep arrays and tuples as is, pass {recurseIntoArrays: false}:
-type A = PartialDeep<Settings>;
+type A = PartialDeep<Settings, {recurseIntoArrays: false}>;If you passed {recurseIntoArrays: true}, you can remove it.
Split and StringToArray options
-type A = Split<Value, '.', {strictLiteralChecks: false}>;
+type A = Split<Value, '.', {strict: false}>;
-type B = StringToArray<Value, {mapNonLiteralsDirectly: true}>;
+type B = StringToArray<Value, {strict: false}>;ReadonlyDeep and Date
ReadonlyDeep now turns a Date into a ReadonlyDate, which has no set* methods. A ReadonlyDate is not assignable to Date.
import type {ReadonlyDeep} from 'type-fest';
type Event = ReadonlyDeep<{start: Date}>;
//=> v5: {readonly start: Date}
//=> v6: {readonly start: ReadonlyDate}If you give the dates to code that expects a Date, change that code to accept a ReadonlyDate, or keep dates as is with the keep option:
type Event = ReadonlyDeep<{start: Date}, {keep: Date}>;
//=> {readonly start: Date}Predicates with never and any
Predicates that returned never for a never input now return false. A conditional type that reads the result now goes to the false branch. Before, it gave never.
import type {IsFloat, IsNull} from 'type-fest';
type A = IsFloat<never>;
//=> v5: never
//=> v6: false
type B = IsNull<any>;
//=> v5: true
//=> v6: falseTsConfigJson
These compilerOptions were removed, because TypeScript removed them or TypeScript 6 deprecated them:
baseUrloutFiledownlevelIterationcharsetimportsNotUsedAsValuespreserveValueImportskeyofStringsOnlynoImplicitUseStrictnoStrictGenericCheckssuppressExcessPropertyErrorssuppressImplicitAnyIndexErrorswatchfallbackPollingwatchDirectorywatchFile(usewatchOptions)listFilesOnly
These values were removed:
module:'None','AMD','UMD','System'moduleResolution:'Classic','Node','Node10'target:'ES3','ES5'lib:'ES2022.SharedMemory'(TypeScript has no lib with this name)alwaysStrict,esModuleInterop, andallowSyntheticDefaultImportsaccept onlytrue.
The TsConfigJson.CompilerOptions.ImportsNotUsedAsValues, FallbackPolling, WatchDirectory, and WatchFile types were also removed. Use the types in TsConfigJson.WatchOptions instead of the last three.