Closed as not planned
Closed as not planned
Description
🔎 Search Terms
keyof
type narrowing
exactOptionalPropertyTypes
🕗 Version & Regression Information
- This is newly identified as error by the compiler
- This changed between versions nightly build on 9/13 and 9/14
- This is the behavior in every version I tried prior to Nightly
⏯ Playground Link
💻 Code
// @strict: true
// @exactOptionalPropertyTypes: true
export interface IBase {
_brand: any;
}
export interface IDerivedA extends IBase {
propertyA?: boolean;
}
export interface IDerivedB extends IBase {
propertyB?: string;
}
export type IAllOptions = IBase &
IDerivedA &
IDerivedB;
export function cloneOptions(
src: IAllOptions,
dest = emptyOptions<IAllOptions>(),
) {
(Object.keys(src) as (keyof IAllOptions)[]).forEach(p => {
if (typeof src[p] !== "object") {
dest[p] = src[p];
}
});
return dest;
}
function emptyOptions<T extends IAllOptions>(): T {
return { _brand: void 0 } as T;
}
🙁 Actual behavior
There is an error on the line attempting to copy src[p]
into dest[p]
:
type 'any' is not assignable to type 'never'.
🙂 Expected behavior
Previously this compiled without error. Both objects are of the same type, so they should have the same properties.
Additional information about the issue
No response