Source

namespace/children/ChildClass.ts

  1. import { Class } from "../Class";
  2. import { ChildInterface } from "./ChildInterface";
  3. /**
  4. * @class ChildClass
  5. * @description This class extends the base Class and implements the ChildInterface.
  6. * @summary Generic class extending Class and implementing ChildInterface with additional functionality.
  7. * It provides a generic implementation with additional properties and methods.
  8. *
  9. * @param {unknown} arg1 - First argument of unknown type
  10. * @param {string} arg2 - Second argument as string
  11. *
  12. * @template T - The generic type parameter
  13. * @extends {Class}
  14. * @implements {ChildInterface<T>}
  15. */
  16. export class ChildClass<T> extends Class implements ChildInterface<T> {
  17. /**
  18. * @description A private property of generic type T.
  19. * @template {T}
  20. * @summary Stores the first constructor argument for later use.
  21. * @private
  22. * @type {T}
  23. */
  24. private prop2?: T;
  25. constructor(arg1: T, arg2: string) {
  26. super(arg1, arg2);
  27. this.prop2 = arg1;
  28. }
  29. /**
  30. * @description This method overrides the base class method.
  31. * @summary Asynchronous method that returns a string after a series of type assertions.
  32. *
  33. * @template V - The generic type parameter
  34. * @return {Promise<string>} A Promise that resolves to a string
  35. * @override
  36. */
  37. override async method<V>(): Promise<string> {
  38. return "ok" as unknown as V as unknown as string;
  39. }
  40. /**
  41. * @description This method implements the method2 from ChildInterface.
  42. * @summary Method that throws an error with a message that includes the input argument.
  43. *
  44. * @param {T} arg1 - The input argument of generic type T
  45. * @return {Promise<string>} A Promise that always rejects with an error
  46. * @throws {Error} Always throws an error with a message including arg1
  47. */
  48. method2(arg1: T): Promise<string> {
  49. throw new Error("error" + arg1);
  50. }
  51. }