Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

problem with interfaces #139

Closed
mhegazy opened this issue Jan 7, 2016 · 4 comments
Closed

problem with interfaces #139

mhegazy opened this issue Jan 7, 2016 · 4 comments
Assignees
Milestone

Comments

@mhegazy
Copy link
Contributor

mhegazy commented Jan 7, 2016

From @jeevan-reddy on December 20, 2015 16:56

Error:
Argument of type '{ size: number; label: string; }' is not assignable to parameter of type '{ label: string; }'.
Object literal may only specify known properties, and 'size' does not exist in type '{ label: string; }'.

My typesscript version is 1.7.5

Steps to recreate the Error:

  1. Create a .ts file named script.ts
  2. type the following code :
function printLabel(labelledObj: {label: string}) {
  console.log(labelledObj.label);
}
var myObj = {size: 10, label: "Size 10 Object"};  // myObj is of type {size:number;label:string}
// printLabel(myObj);
printLabel({size: 10, label: "Size 10 Object"});   // the object being passed to printLabel is also of type {size:number;label:string}
  1. Compile the script.ts using command tsc script either from command prompt/powershell

it is clearly mentioned in documentation that if we send extra arguments it is ok .please refer to attached code-snippet
code-snippet

But what is the difference if i assign an object to a variable , pass that variable as argument and if i directly pass the object as argument ?

Copied from original issue: microsoft/TypeScript#6175

@mhegazy
Copy link
Contributor Author

mhegazy commented Jan 7, 2016

From @kitsonk on December 20, 2015 17:49

The handbook is currently wrong as of TypeScript 1.6.3. It was discussed in #3755 and was changed in #3823.

IIRC, the team are in the process of doing a whole update of the handbook, because there are a few other issues with it.

@mhegazy
Copy link
Contributor Author

mhegazy commented Jan 7, 2016

From @DanielRosenwasser on December 20, 2015 20:47

Thanks for catching this @jeevan-reddy, I'll be amending this in #64

@DanielRosenwasser
Copy link
Member

Duplicate of #64.

@madroneropaulo
Copy link

Could you please at least add a warning message in the handbook like "Some of this information may be outdated"? I mean, I lost some time trying to figure out whats wrong with my code while following this handbook for learning typescript. A version warning message would be enough for considering the problem as a version incongruity.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants