Skip to content

Conversation

@Schrubitteflau
Copy link
Contributor

Create 3 specialized Difference interfaces which allows us to have some type-hinting when the value of the property type is tested :

const differences: Difference[] = diff({}, {});

for (const difference of differences) {
	switch (difference.type) {
		case "CREATE":
			console.log(difference); // type-hint : DifferenceCreate
			difference.oldValue; // Property 'oldValue' does not exist on type 'DifferenceCreate'
			break;
		case "REMOVE":
			console.log(difference); // type-hint : DifferenceRemove
			difference.value; // Property 'value' does not exist on type 'DifferenceRemove'
			break;
		case "CHANGE":
			console.log(difference); // type-hint : DifferenceChange
			difference.value // OK
			difference.oldValue // OK
			break;
	}
}

@AsyncBanana
Copy link
Owner

Looks good! It should help the development experience with TypeScript. Thanks for the PR!

@AsyncBanana AsyncBanana merged commit c803311 into AsyncBanana:master Jul 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants