Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

problem with interfaces #6175

Closed
jeevan-reddy opened this issue Dec 20, 2015 · 4 comments
Closed

problem with interfaces #6175

jeevan-reddy opened this issue Dec 20, 2015 · 4 comments
Assignees
Labels
Docs The issue relates to how you learn TypeScript

Comments

@jeevan-reddy
Copy link

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 ?

@kitsonk
Copy link
Contributor

kitsonk commented Dec 20, 2015

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.

@DanielRosenwasser
Copy link
Member

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

@DanielRosenwasser DanielRosenwasser added the Docs The issue relates to how you learn TypeScript label Dec 20, 2015
@DanielRosenwasser DanielRosenwasser added this to the TypeScript 1.8 milestone Dec 20, 2015
@DanielRosenwasser DanielRosenwasser self-assigned this Dec 20, 2015
@mhegazy
Copy link
Contributor

mhegazy commented Jan 7, 2016

This issue was moved to microsoft/TypeScript-Handbook#139

@DanielRosenwasser
Copy link
Member

Should be fixed when the docs get refreshed.

@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Docs The issue relates to how you learn TypeScript
Projects
None yet
Development

No branches or pull requests

4 participants