Skip to content

add type checking to decorators#230626

Merged
mjbvz merged 2 commits intomicrosoft:mainfrom
yanglb:improve-decorator
Oct 18, 2024
Merged

add type checking to decorators#230626
mjbvz merged 2 commits intomicrosoft:mainfrom
yanglb:improve-decorator

Conversation

@yanglb
Copy link
Copy Markdown
Contributor

@yanglb yanglb commented Oct 6, 2024

Add type check support to decorators.

Why?

The return value of decorators @memoize, @debounce and @throttle is of type Function, which does not support TS type checking.

This PR ensures decorators are used correctly, for example:

@memoize // ❌ The compiler should report an error
export class UserInfo {
	@memoize // ❌ report an error
	firstName?: string;
	lastName?: string;

	saveTo(@memoize /* ❌ report an error */ file: string) {
		// TODO
	}

	@memoize // ✅ support getter
	get name() {
		return `${this.firstName} ${this.lastName}`;
	}

	@memoize // ✅ support method
	toString() {
		return this.name;
	}
}

@yanglb
Copy link
Copy Markdown
Contributor Author

yanglb commented Oct 6, 2024

@microsoft-github-policy-service agree

@mjbvz mjbvz enabled auto-merge (rebase) October 7, 2024 18:58
Copy link
Copy Markdown
Collaborator

@mjbvz mjbvz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@vs-code-engineering vs-code-engineering bot added this to the October 2024 milestone Oct 7, 2024
@mjbvz mjbvz merged commit 277082f into microsoft:main Oct 18, 2024
@vs-code-engineering vs-code-engineering bot locked and limited conversation to collaborators Dec 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants