{"action":"created","issue":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/195","labels_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/195/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/195/comments","events_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/195/events","html_url":"https://github.com/Microsoft/TypeScript/issues/195","id":38430494,"number":195,"title":"Suggestion: int type","user":{"login":"fdecampredon","id":864201,"avatar_url":"https://avatars.githubusercontent.com/u/864201?v=3","gravatar_id":"","url":"https://api.github.com/users/fdecampredon","html_url":"https://github.com/fdecampredon","followers_url":"https://api.github.com/users/fdecampredon/followers","following_url":"https://api.github.com/users/fdecampredon/following{/other_user}","gists_url":"https://api.github.com/users/fdecampredon/gists{/gist_id}","starred_url":"https://api.github.com/users/fdecampredon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fdecampredon/subscriptions","organizations_url":"https://api.github.com/users/fdecampredon/orgs","repos_url":"https://api.github.com/users/fdecampredon/repos","events_url":"https://api.github.com/users/fdecampredon/events{/privacy}","received_events_url":"https://api.github.com/users/fdecampredon/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/Microsoft/TypeScript/labels/Needs%20Proposal","name":"Needs Proposal","color":"556b75"},{"url":"https://api.github.com/repos/Microsoft/TypeScript/labels/Suggestion","name":"Suggestion","color":"006b75"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":15,"created_at":"2014-07-22T18:43:18Z","updated_at":"2015-06-27T04:42:15Z","closed_at":null,"body":"Introducing `int` type could allows some  error to be caught at compile time (like trying to index an array with a float) and perhaps improve performance of outputted javascript, to obtains true `int`, TypeScript could systematically emit a cas with `|0` when a variable/parameter is an integer :\r\n\r\n```typescript \r\nvar i: int; \r\nvar n: number;\r\nvar a: any = 1.2;\r\ni = 1.1; // error;\r\ni = n; // error\r\ni = 3 / 4; // valid, type casted\r\ni = a; // valid, type casted\r\n\r\nvar indexable: { [i: int]: bool } = {};\r\nindexable[n] = true; // error\r\nindexable[i] = true; // valid\r\nindexable[i/2] = true; // valid, type casted\r\nindexable[a] = true; // valid, type casted\r\n\r\nfunction logInt(i: int) {\r\n  console.log(i);\r\n}\r\n```\r\nwould emit\r\n```javascript\r\nvar n;\r\nvar i = i | 0;\r\nvar a = 1.2;\r\ni = 1.1 // error;\r\ni = n // error\r\ni = (3 / 4 ) | 0; // valid, type casted\r\ni = a | 0; // valid, type casted\r\n\r\nvar indexable= {};\r\nindexable[n] = true; // error\r\nindexable[i] = true; // valid\r\nindexable[(i / 2) | 0] = true; // valid, type casted\r\nindexable[a | 0] = true; // valid, type casted\r\n\r\nfunction logInt(i: int) {\r\n  i = i | 0;\r\n  console.log(i);\r\n}\r\n```\r\n\r\nThere will perhaps be a problem with generic and method but I guess the compiler could in this case type cast when passing the parameter:\r\n\r\n```typescript\r\nfunction add<T>(a: T,b: T): T {\r\n  return a + b;\r\n}  \r\n\r\nvar a = add(1, 2); // a is number value 3\r\nvar b = add<int>(1/2, 2); // b is int, value 2\r\nvar c = add(1/2, 2); // c is number, value 2.5\r\n```\r\n\r\nemit :\r\n```javascript\r\nfunction add(a, b) {\r\n  return a + b;\r\n}\r\nvar a = add(1, 2); // a is number value 3\r\nvar b = add<int>((1/2)| 0, 2);\r\nvar c = add(1/2, 2); // c is number, value 2.5\r\n```\r\nalso perhaps the compiler should always infer 'number' if there is not explicit type annotation\r\n\r\n```typescript\r\nvar n = 3 //number\r\nvar i: int  = 3 //int\r\n```"},"comment":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/comments/115958906","html_url":"https://github.com/Microsoft/TypeScript/issues/195#issuecomment-115958906","issue_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/195","id":115958906,"user":{"login":"aholmes","id":277061,"avatar_url":"https://avatars.githubusercontent.com/u/277061?v=3","gravatar_id":"","url":"https://api.github.com/users/aholmes","html_url":"https://github.com/aholmes","followers_url":"https://api.github.com/users/aholmes/followers","following_url":"https://api.github.com/users/aholmes/following{/other_user}","gists_url":"https://api.github.com/users/aholmes/gists{/gist_id}","starred_url":"https://api.github.com/users/aholmes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aholmes/subscriptions","organizations_url":"https://api.github.com/users/aholmes/orgs","repos_url":"https://api.github.com/users/aholmes/repos","events_url":"https://api.github.com/users/aholmes/events{/privacy}","received_events_url":"https://api.github.com/users/aholmes/received_events","type":"User","site_admin":false},"created_at":"2015-06-27T04:42:15Z","updated_at":"2015-06-27T04:42:15Z","body":"Another point for integer and float types are for writing definition files. When APIs call for specifically an int or a float, it is dishonest to claim that the type is a number."}}