Skip to content

Argument of type 'MyType<E>' is not assignable to parameter of type 'Partial<MyType<E>>' #310

Open
@ndr47

Description

@ndr47

I have a code that give me an error only in VIM. If I try the same code in VisualStudio or Typescript Playground there error disappear.

The error is:

Argument of type 'ElementShape<E>' is not assignable to parameter of type 'Partial<ElementShape<E>>'

This is the code:

const element_def = {
	element1: {
		name: {
		}
	},
	element2: {
		age: {
		}
	}
} as const;

const element_def_optional = {
	element1: {
		title: {
		}
	},
	element2: {
		price: {
		}
	}
} as const;

export type ElementName = 'element1' | 'element2';

export type ElementShape<A extends ElementName> = {
	[k in keyof typeof element_def[A]]: string
} & {
	[k in keyof typeof element_def_optional[A]]?: string
};

function process_partial<E extends ElementName>(name: E, partial:Partial<ElementShape<E>>){
	console.log(name, partial);
}

export function process_shape<E extends ElementName>(name: E, shape:ElementShape<E>):void{
	process_partial(name, shape);
                                            // ~~~ Error: Argument of type 'ElementShape<E>' is not assignable to parameter of type 'Partial<ElementShape<E>>'
}

Playground Link

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions