Skip to content

Commit

Permalink
Add TypeScript linter check
Browse files Browse the repository at this point in the history
  • Loading branch information
TimvdLippe committed Jun 30, 2018
1 parent 777dbc8 commit efe662b
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 13 deletions.
11 changes: 6 additions & 5 deletions dist/polyfill.js
Expand Up @@ -5,8 +5,7 @@
}(this, (function () { 'use strict';

/**
* @constructor
* @extends {Promise}
* @this {Promise}
*/
function finallyConstructor(callback) {
var constructor = this.constructor;
Expand Down Expand Up @@ -39,6 +38,7 @@ function bind(fn, thisArg) {

/**
* @constructor
* @param {Function} fn
*/
function Promise(fn) {
if (!(this instanceof Promise))
Expand Down Expand Up @@ -173,6 +173,7 @@ Promise.prototype['catch'] = function(onRejected) {
};

Promise.prototype.then = function(onFulfilled, onRejected) {
// @ts-ignore
var prom = new this.constructor(noop);

handle(this, new Handler(onFulfilled, onRejected, prom));
Expand Down Expand Up @@ -259,7 +260,7 @@ Promise._unhandledRejectionFn = function _unhandledRejectionFn(err) {
}
};

var global;
/** @suppress {undefinedVars} */
var globalNS = (function() {
// the only reliable means to get the global object is
// `Function('return this')()`
Expand All @@ -276,8 +277,8 @@ var globalNS = (function() {
throw new Error('unable to locate global object');
})();

if (!globalNS.Promise) {
globalNS.Promise = Promise;
if (!('Promise' in globalNS)) {
globalNS['Promise'] = Promise;
} else if (!globalNS.Promise.prototype['finally']) {
globalNS.Promise.prototype['finally'] = finallyConstructor;
}
Expand Down
2 changes: 1 addition & 1 deletion dist/polyfill.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Expand Up @@ -15,7 +15,8 @@
"precommit": "lint-staged",
"pretest": "npm run build:cjs",
"closure": "google-closure-compiler --js=src/*.js --checks_only --module_resolution=node --compilation_level=ADVANCED",
"lint": "eslint src && npm run closure",
"typescript": "tsc --checkJS --allowJS --noEmit src/**",
"lint": "eslint src && npm run closure && npm run typescript",
"test": "npm run lint && mocha && karma start --single-run",
"prebuild": "rimraf lib dist",
"build": "run-p build:**",
Expand Down Expand Up @@ -53,7 +54,8 @@
"rimraf": "^2.6.2",
"rollup": "^0.52.0",
"rollup-plugin-uglify": "^2.0.1",
"sinon": "^1.17.2"
"sinon": "^1.17.2",
"typescript": "^2.9.2"
},
"keywords": [
"promise",
Expand Down
3 changes: 1 addition & 2 deletions src/finally.js
@@ -1,6 +1,5 @@
/**
* @constructor
* @extends {Promise}
* @this {Promise}
*/
function finallyConstructor(callback) {
var constructor = this.constructor;
Expand Down
2 changes: 2 additions & 0 deletions src/index.js
Expand Up @@ -15,6 +15,7 @@ function bind(fn, thisArg) {

/**
* @constructor
* @param {Function} fn
*/
function Promise(fn) {
if (!(this instanceof Promise))
Expand Down Expand Up @@ -149,6 +150,7 @@ Promise.prototype['catch'] = function(onRejected) {
};

Promise.prototype.then = function(onFulfilled, onRejected) {
// @ts-ignore
var prom = new this.constructor(noop);

handle(this, new Handler(onFulfilled, onRejected, prom));
Expand Down
6 changes: 3 additions & 3 deletions src/polyfill.js
@@ -1,7 +1,7 @@
import Promise from './index';
import promiseFinally from './finally';

var global;
/** @suppress {undefinedVars} */
var globalNS = (function() {
// the only reliable means to get the global object is
// `Function('return this')()`
Expand All @@ -18,8 +18,8 @@ var globalNS = (function() {
throw new Error('unable to locate global object');
})();

if (!globalNS.Promise) {
globalNS.Promise = Promise;
if (!('Promise' in globalNS)) {
globalNS['Promise'] = Promise;
} else if (!globalNS.Promise.prototype['finally']) {
globalNS.Promise.prototype['finally'] = promiseFinally;
}

0 comments on commit efe662b

Please sign in to comment.