diff --git a/cocos/scene-graph/node.ts b/cocos/scene-graph/node.ts index 088f8b50fcc..821a20f1f43 100644 --- a/cocos/scene-graph/node.ts +++ b/cocos/scene-graph/node.ts @@ -877,7 +877,7 @@ export class Node extends CCObject implements ISchedulable, CustomSerializable { * var test = node.getComponent("Test"); * ``` */ - public getComponent(className: string): Component | null; + public getComponent(className: string): T | null; public getComponent (typeOrClassName: string | Constructor | AbstractedConstructor): T | null { const constructor = getConstructor(typeOrClassName); @@ -899,11 +899,11 @@ export class Node extends CCObject implements ISchedulable, CustomSerializable { * @zh 返回节点上指定类型的所有组件。 * @param className The class name of the target component */ - public getComponents(className: string): Component[]; + public getComponents(className: string): T[]; - public getComponents (typeOrClassName: string | Constructor | AbstractedConstructor): Component[] { + public getComponents (typeOrClassName: string | Constructor | AbstractedConstructor): T[] { const constructor = getConstructor(typeOrClassName); - const components: Component[] = []; + const components: T[] = []; if (constructor) { Node._findComponents(this, constructor, components); } @@ -930,7 +930,7 @@ export class Node extends CCObject implements ISchedulable, CustomSerializable { * var Test = node.getComponentInChildren("Test"); * ``` */ - public getComponentInChildren(className: string): Component | null; + public getComponentInChildren(className: string): T | null; public getComponentInChildren (typeOrClassName: string | Constructor | AbstractedConstructor): T | null { const constructor = getConstructor(typeOrClassName); @@ -960,11 +960,11 @@ export class Node extends CCObject implements ISchedulable, CustomSerializable { * var tests = node.getComponentsInChildren("Test"); * ``` */ - public getComponentsInChildren(className: string): Component[]; + public getComponentsInChildren(className: string): T[]; - public getComponentsInChildren (typeOrClassName: string | Constructor | AbstractedConstructor): Component[] { + public getComponentsInChildren (typeOrClassName: string | Constructor | AbstractedConstructor): T[] { const constructor = getConstructor(typeOrClassName); - const components: Component[] = []; + const components: T[] = []; if (constructor) { Node._findComponents(this, constructor, components); Node._findChildComponents(this._children, constructor, components); @@ -994,7 +994,7 @@ export class Node extends CCObject implements ISchedulable, CustomSerializable { * var test = node.addComponent("Test"); * ``` */ - public addComponent(className: string): Component; + public addComponent(className: string): T; public addComponent (typeOrClassName: string | Constructor): T { if (EDITOR && (this._objFlags & Destroying)) {