This behavior is specific to TypeScript. In JavaScript, everything is considered an object, including strings and other data types.
When using the Partial type in TS, it does not throw an error because strings are a type of object. However, making all keys optional may not have any practical effect.
string extends Object ? true : false //=> returns true
To avoid this behavior or if you require a stricter version of Partial, consider using something like extends Record<any, any>
string extends Record<any, any> ? true : false //=> returns false
//We can redefine our Partial function as follows
type PartialStrict<T extends Record<any, any>> = Partial<T>
type test2 = PartialStrict<string> //Error! Type 'string' does not satisfy the constraint 'Record<any, any>'.
Link to Playground