7 kyu

Learning TypeScript. Classes & Interfaces. Inheritance

Description
Loading description...
Fundamentals
Object-oriented Programming
View
AllIssues2Questions1SuggestionsShow Resolved
  • Please sign in or sign up to leave a comment.
  • Ching Ching Avatar
    The constructor function for Animal should accept 4 arguments in total in the following order: name, age, legs, species, status.
    

    The description is incorrect: there are 5 arguments, not 4.

  • cyberjar09 Avatar
    declare var IAnimal: {
      new (
        name: string,
        age: number,
        legs: number,
        species: string,
        status: string
      ): IAnimal;
    }
    

    Is the declare necessary? What purpose does it serve? Can you please point me to the relevant documentation to learn more about whats going on here? My solution worked when I commented it out.

  • max30272 Avatar

    Is this a "Learning TypeScript" series? Even the orignal one is more friendly than this.
    I'm totally new to TypeScript.And I need to search for more informations in every kata of this series.

  • jomungand Avatar

    Seems to be broken. I'm getting

    /runner/node_modules/ts-node/src/index.ts:307 throw new TSError(formatDiagnostics(diagnosticList, cwd, ts, lineOffset)) ^ TSError: ⨯ Unable to compile TypeScript spec.ts (3,39): File '/home/codewarrior/solution.ts' is not a module. (2306) spec.ts (55,77): Property 'introduce' does not exist on type 'Solution'. (2339) at getOutput (/runner/node_modules/ts-node/src/index.ts:307:15) at /runner/node_modules/ts-node/src/index.ts:336:16 at Object.compile (/runner/node_modules/ts-node/src/index.ts:498:11) at Module.m._compile (/runner/node_modules/ts-node/src/index.ts:392:43) at Module._extensions..js (module.js:635:10) at Object.require.extensions.(anonymous function) [as .ts] (/runner/node_modules/ts-node/src/index.ts:395:12) at Module.load (module.js:545:32) at tryModuleLoad (module.js:508:12) at Function.Module._load (module.js:500:3) at Module.require (module.js:568:17) at require (internal/module.js:11:18) at /runner/node_modules/mocha/lib/mocha.js:231:27 at Array.forEach (<anonymous>) at Mocha.loadFiles (/runner/node_modules/mocha/lib/mocha.js:228:14) at Mocha.run (/runner/node_modules/mocha/lib/mocha.js:514:10) at Object.<anonymous> (/runner/node_modules/mocha/bin/_mocha:480:18) at Module._compile (module.js:624:30) at Object.Module._extensions..js (module.js:635:10) at Module.load (module.js:545:32) at tryModuleLoad (module.js:508:12) at Function.Module._load (module.js:500:3) at Function.Module.runMain (module.js:665:10) at startup (bootstrap_node.js:187:16) at bootstrap_node.js:608:3

  • Voile Avatar

    Approved

  • siebenschlaefer Avatar

    What is the purpose of the IAnimal variable declaration?

    declare var IAnimal: {
      new (
        name: string,
        age: number,
        legs: number,
        species: string,
        status: string
      ): IAnimal;
    }
    

    IMHO the solution doesn't need it, but then again, I just started with TypeScript.

    • siebenschlaefer Avatar

      And why is introduce declared as returning void if it is supposed to return a string? Is that part of the task?

    • vguzev Avatar

      This is actually a "hack" to define the constructor parameters in interfaces. For example see how Typescript's team did the same in defining Object interface: https://github.com/Microsoft/TypeScript/blob/master/lib/lib.d.ts They are declaring an interface and afterwards a variable with a name matching exactly the interface-name. This is also the way to type static functions. So, yes, this is part of the task.

      P.S. introduce is now returning string. Thanks for your report!

    • Voile Avatar

      This comment has been hidden.

      Question marked resolved by Voile 8 years ago