Closed existe-deja closed 10 months ago
defu 6.1.3
live code https://stackblitz.com/edit/typescript-ztqwq7?file=index.ts
import defu from 'defu'; type Source = { a: string; some: string; }; type Target = { a: number; }; const source: Source = { a: '1', some: 'props', }; const target: Target = { a: parseFloat(source.a), }; // type of merged['a'] is string | number instead of number const merged = defu(target, source); console.log(merged);
I'm not sure if it's a bug or a feature but when both object share the same property, defu merges types instead of overwriting it.
No response
I think the behavior was expected, and you can get the same result by doing the following:
import type { Defu } from 'defu'; type Options = Defu<Source, [Target]>
Environment
defu 6.1.3
Reproduction
live code https://stackblitz.com/edit/typescript-ztqwq7?file=index.ts
Describe the bug
I'm not sure if it's a bug or a feature but when both object share the same property, defu merges types instead of overwriting it.
Additional context
No response
Logs
No response