Skip to content

Instantly share code, notes, and snippets.

@fkowal
Last active November 9, 2015 06:54
Show Gist options
  • Save fkowal/2e08964fa302a09696e4 to your computer and use it in GitHub Desktop.
Save fkowal/2e08964fa302a09696e4 to your computer and use it in GitHub Desktop.
Intellij typescript type inference bug
# Created by .ignore support plugin (hsz.mobi)
/node_modules/
phantomjsdriver.log
/.tscache/
*.js.map
*.js
typings/
.idea/
reference.js

Instalation

npm install npm run grunt tsd

Open project in intellij. Bugs are localed in

src/bug.ts

src/bug2.ts

///<reference path="typings/tsd.d.ts"/>
import Rx = require('rx');
var cok = Rx.Observable.fromPromise(browser.manage().getCookie('test'));
cok.map(function(val, idx, src) {
// type inference is broken in intellij (works fine in sublime)
return val.value;
});
///<reference path="typings/tsd.d.ts"/>
import Rx = require('rx');
class Y {
el: string[] = ['a','b','c']
}
class X {
constructor(public data: Y[], public str: string) {
}
}
var x = new X([new Y], "test");
var source = Rx.Observable.of(x);
source.map(function(x_with_infered_type) {
// type inference sort of works on this level
return x_with_infered_type.; // i ctrl+space show "data, el, str" and others so not really ok
}).map(function(y_arr) {
y_arr. // ctrl+space shows data, el, str
// type inference is broken in intellij works in sublime
//y_arr[0].
})
module.exports = function (grunt) {
grunt.initConfig({
ts: {
default: {
src: ["reference.ts", "bug.ts", "bug2.ts"],
reference: "reference.ts",
options: {
module: "commonjs"
}
}
},
tsd: {
default: {
options: {
// execute a command
command: 'reinstall',
//optional: always get from HEAD
latest: true,
// specify config file
config: 'tsd.json',
// experimental: options to pass to tsd.API
opts: {
// props from tsd.Options
}
}
}
}
});
grunt.loadNpmTasks('grunt-ts');
grunt.loadNpmTasks('grunt-tsd');
grunt.loadNpmTasks('grunt-traceur');
grunt.registerTask('default', ['tsd','ts']);
}
{
"name": "typescript-type-inference-bug",
"version": "0.0.0",
"description": "Bug in intellij with typescript",
"main": "index.js",
"scripts": {
"grunt": "grunt"
},
"license": "ISC",
"dependencies": {
"grunt": "~0.4.5",
"rx": "^2.5",
"grunt-ts": "~4.2.0-beta.1"
},
"devDependencies": {
"grunt-tsd": "~0.2.0-beta.1",
"tsd": "~0.5.7"
}
}
//grunt-start
/// <reference path="bug.ts" />
/// <reference path="bug2.ts" />
//grunt-end
{
"version": "v4",
"repo": "borisyankov/DefinitelyTyped",
"ref": "master",
"path": "typings",
"bundle": "typings/tsd.d.ts",
"installed": {
"angular-protractor/angular-protractor.d.ts": {
"commit": "76e1dedf0bada455c0b75abeec3206d3aa5bd892"
},
"selenium-webdriver/selenium-webdriver.d.ts": {
"commit": "76e1dedf0bada455c0b75abeec3206d3aa5bd892"
},
"rx/rx.d.ts": {
"commit": "76e1dedf0bada455c0b75abeec3206d3aa5bd892"
},
"rx/rx-lite.d.ts": {
"commit": "76e1dedf0bada455c0b75abeec3206d3aa5bd892"
},
"rx/rx.time-lite.d.ts": {
"commit": "76e1dedf0bada455c0b75abeec3206d3aa5bd892"
},
"rx/rx.time.d.ts": {
"commit": "76e1dedf0bada455c0b75abeec3206d3aa5bd892"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment