[TypeScript][Node] Resolve errors for strict compile (#6933)

* [TypeScript][Node] Resolve TS7017 error

* Run `bin/typescript-node-petstore-all.sh`

* Run `bin/security/typescript-node.sh`

* Add `strict` option to ts-node config

* Run `bin/typescript-node-petstore-all.sh`

* Fix `strict` option syntax in typescript-node/tsconfig.mustache

* Sync tsconfig.json

* Sync package.json

* Delete typings.json

* Sync tsconfig.json

* Resolve TS2345 error

* Resolve TS2322 in integration-test (Delete non-effective codes)

* Add @types/rewire to test

* Resolve TS7017 errors

* Run `bin/typescript-node-petstore-all.sh`

* Run `bin/security/typescript-node.sh`
This commit is contained in:
Shuma Yoshioka
2017-11-16 18:00:48 +09:00
committed by William Cheng
parent 818ff8f245
commit 85b0d0ff78
18 changed files with 601 additions and 1820 deletions

View File

@@ -63,7 +63,7 @@ class ObjectSerializer {
} else if (type.lastIndexOf("Array<", 0) === 0) { // string.startsWith pre es6
let subType: string = type.replace("Array<", ""); // Array<Type> => Type>
subType = subType.substring(0, subType.length - 1); // Type> => Type
let transformedData = [];
let transformedData: any[] = [];
for (let index in data) {
let date = data[index];
transformedData.push(ObjectSerializer.serialize(date, subType));
@@ -81,7 +81,7 @@ class ObjectSerializer {
// get the map for the correct type.
let attributeTypes = typeMap[type].getAttributeTypeMap();
let instance = {};
let instance: {[index: string]: any} = {};
for (let index in attributeTypes) {
let attributeType = attributeTypes[index];
instance[attributeType.baseName] = ObjectSerializer.serialize(data[attributeType.name], attributeType.type);
@@ -100,7 +100,7 @@ class ObjectSerializer {
} else if (type.lastIndexOf("Array<", 0) === 0) { // string.startsWith pre es6
let subType: string = type.replace("Array<", ""); // Array<Type> => Type>
subType = subType.substring(0, subType.length - 1); // Type> => Type
let transformedData = [];
let transformedData: any[] = [];
for (let index in data) {
let date = data[index];
transformedData.push(ObjectSerializer.deserialize(date, subType));
@@ -190,7 +190,7 @@ export namespace {{classname}} {
{{/model}}
{{/models}}
let enumsMap = {
let enumsMap: {[index: string]: any} = {
{{#models}}
{{#model}}
{{#hasEnums}}
@@ -204,7 +204,7 @@ let enumsMap = {
{{/models}}
}
let typeMap = {
let typeMap: {[index: string]: any} = {
{{#models}}
{{#model}}
"{{classname}}": {{classname}},
@@ -339,7 +339,7 @@ export class {{classname}} {
}
public setApiKey(key: {{classname}}ApiKeys, value: string) {
this.authentications[{{classname}}ApiKeys[key]].apiKey = value;
(this.authentications as any)[{{classname}}ApiKeys[key]].apiKey = value;
}
{{#authMethods}}
{{#isBasic}}

View File

@@ -4,6 +4,7 @@
"noImplicitAny": false,
"suppressImplicitAnyIndexErrors": true,
"target": "{{#supportsES6}}ES6{{/supportsES6}}{{^supportsES6}}ES5{{/supportsES6}}",
"strict": true,
"moduleResolution": "node",
"removeComments": true,
"sourceMap": true,
@@ -15,4 +16,3 @@
"node_modules"
]
}

View File

@@ -72,7 +72,7 @@ class ObjectSerializer {
} else if (type.lastIndexOf("Array<", 0) === 0) { // string.startsWith pre es6
let subType: string = type.replace("Array<", ""); // Array<Type> => Type>
subType = subType.substring(0, subType.length - 1); // Type> => Type
let transformedData = [];
let transformedData: any[] = [];
for (let index in data) {
let date = data[index];
transformedData.push(ObjectSerializer.serialize(date, subType));
@@ -90,7 +90,7 @@ class ObjectSerializer {
// get the map for the correct type.
let attributeTypes = typeMap[type].getAttributeTypeMap();
let instance = {};
let instance: {[index: string]: any} = {};
for (let index in attributeTypes) {
let attributeType = attributeTypes[index];
instance[attributeType.baseName] = ObjectSerializer.serialize(data[attributeType.name], attributeType.type);
@@ -109,7 +109,7 @@ class ObjectSerializer {
} else if (type.lastIndexOf("Array<", 0) === 0) { // string.startsWith pre es6
let subType: string = type.replace("Array<", ""); // Array<Type> => Type>
subType = subType.substring(0, subType.length - 1); // Type> => Type
let transformedData = [];
let transformedData: any[] = [];
for (let index in data) {
let date = data[index];
transformedData.push(ObjectSerializer.deserialize(date, subType));
@@ -160,10 +160,10 @@ export class ModelReturn {
}
let enumsMap = {
let enumsMap: {[index: string]: any} = {
}
let typeMap = {
let typeMap: {[index: string]: any} = {
"ModelReturn": ModelReturn,
}
@@ -262,7 +262,7 @@ export class FakeApi {
}
public setApiKey(key: FakeApiApiKeys, value: string) {
this.authentications[FakeApiApiKeys[key]].apiKey = value;
(this.authentications as any)[FakeApiApiKeys[key]].apiKey = value;
}
set accessToken(token: string) {

View File

@@ -36,7 +36,7 @@ git_remote=`git remote`
if [ "$git_remote" = "" ]; then # git remote not defined
if [ "$GIT_TOKEN" = "" ]; then
echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git crediential in your environment."
echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git credential in your environment."
git remote add origin https://github.com/${git_user_id}/${git_repo_id}.git
else
git remote add origin https://${git_user_id}:${GIT_TOKEN}@github.com/${git_user_id}/${git_repo_id}.git

View File

@@ -72,7 +72,7 @@ class ObjectSerializer {
} else if (type.lastIndexOf("Array<", 0) === 0) { // string.startsWith pre es6
let subType: string = type.replace("Array<", ""); // Array<Type> => Type>
subType = subType.substring(0, subType.length - 1); // Type> => Type
let transformedData = [];
let transformedData: any[] = [];
for (let index in data) {
let date = data[index];
transformedData.push(ObjectSerializer.serialize(date, subType));
@@ -90,7 +90,7 @@ class ObjectSerializer {
// get the map for the correct type.
let attributeTypes = typeMap[type].getAttributeTypeMap();
let instance = {};
let instance: {[index: string]: any} = {};
for (let index in attributeTypes) {
let attributeType = attributeTypes[index];
instance[attributeType.baseName] = ObjectSerializer.serialize(data[attributeType.name], attributeType.type);
@@ -109,7 +109,7 @@ class ObjectSerializer {
} else if (type.lastIndexOf("Array<", 0) === 0) { // string.startsWith pre es6
let subType: string = type.replace("Array<", ""); // Array<Type> => Type>
subType = subType.substring(0, subType.length - 1); // Type> => Type
let transformedData = [];
let transformedData: any[] = [];
for (let index in data) {
let date = data[index];
transformedData.push(ObjectSerializer.deserialize(date, subType));
@@ -406,12 +406,12 @@ export class User {
}
let enumsMap = {
let enumsMap: {[index: string]: any} = {
"Order.StatusEnum": Order.StatusEnum,
"Pet.StatusEnum": Pet.StatusEnum,
}
let typeMap = {
let typeMap: {[index: string]: any} = {
"ApiResponse": ApiResponse,
"Category": Category,
"Order": Order,
@@ -515,7 +515,7 @@ export class PetApi {
}
public setApiKey(key: PetApiApiKeys, value: string) {
this.authentications[PetApiApiKeys[key]].apiKey = value;
(this.authentications as any)[PetApiApiKeys[key]].apiKey = value;
}
set accessToken(token: string) {
@@ -1032,7 +1032,7 @@ export class StoreApi {
}
public setApiKey(key: StoreApiApiKeys, value: string) {
this.authentications[StoreApiApiKeys[key]].apiKey = value;
(this.authentications as any)[StoreApiApiKeys[key]].apiKey = value;
}
set accessToken(token: string) {
@@ -1290,7 +1290,7 @@ export class UserApi {
}
public setApiKey(key: UserApiApiKeys, value: string) {
this.authentications[UserApiApiKeys[key]].apiKey = value;
(this.authentications as any)[UserApiApiKeys[key]].apiKey = value;
}
set accessToken(token: string) {

View File

@@ -36,7 +36,7 @@ git_remote=`git remote`
if [ "$git_remote" = "" ]; then # git remote not defined
if [ "$GIT_TOKEN" = "" ]; then
echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git crediential in your environment."
echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git credential in your environment."
git remote add origin https://github.com/${git_user_id}/${git_repo_id}.git
else
git remote add origin https://${git_user_id}:${GIT_TOKEN}@github.com/${git_user_id}/${git_repo_id}.git

View File

@@ -1,3 +1,6 @@
/// <reference types="request" />
/// <reference types="bluebird" />
/// <reference types="node" />
import localVarRequest = require('request');
import http = require('http');
import Promise = require('bluebird');
@@ -5,7 +8,7 @@ export declare class ApiResponse {
'code': number;
'type': string;
'message': string;
static discriminator: any;
static discriminator: undefined;
static attributeTypeMap: Array<{
name: string;
baseName: string;
@@ -20,7 +23,7 @@ export declare class ApiResponse {
export declare class Category {
'id': number;
'name': string;
static discriminator: any;
static discriminator: undefined;
static attributeTypeMap: Array<{
name: string;
baseName: string;
@@ -39,7 +42,7 @@ export declare class Order {
'shipDate': Date;
'status': Order.StatusEnum;
'complete': boolean;
static discriminator: any;
static discriminator: undefined;
static attributeTypeMap: Array<{
name: string;
baseName: string;
@@ -65,7 +68,7 @@ export declare class Pet {
'photoUrls': Array<string>;
'tags': Array<Tag>;
'status': Pet.StatusEnum;
static discriminator: any;
static discriminator: undefined;
static attributeTypeMap: Array<{
name: string;
baseName: string;
@@ -87,7 +90,7 @@ export declare namespace Pet {
export declare class Tag {
'id': number;
'name': string;
static discriminator: any;
static discriminator: undefined;
static attributeTypeMap: Array<{
name: string;
baseName: string;
@@ -108,7 +111,7 @@ export declare class User {
'password': string;
'phone': string;
'userStatus': number;
static discriminator: any;
static discriminator: undefined;
static attributeTypeMap: Array<{
name: string;
baseName: string;

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@@ -72,7 +72,7 @@ class ObjectSerializer {
} else if (type.lastIndexOf("Array<", 0) === 0) { // string.startsWith pre es6
let subType: string = type.replace("Array<", ""); // Array<Type> => Type>
subType = subType.substring(0, subType.length - 1); // Type> => Type
let transformedData = [];
let transformedData: any[] = [];
for (let index in data) {
let date = data[index];
transformedData.push(ObjectSerializer.serialize(date, subType));
@@ -90,7 +90,7 @@ class ObjectSerializer {
// get the map for the correct type.
let attributeTypes = typeMap[type].getAttributeTypeMap();
let instance = {};
let instance: {[index: string]: any} = {};
for (let index in attributeTypes) {
let attributeType = attributeTypes[index];
instance[attributeType.baseName] = ObjectSerializer.serialize(data[attributeType.name], attributeType.type);
@@ -109,7 +109,7 @@ class ObjectSerializer {
} else if (type.lastIndexOf("Array<", 0) === 0) { // string.startsWith pre es6
let subType: string = type.replace("Array<", ""); // Array<Type> => Type>
subType = subType.substring(0, subType.length - 1); // Type> => Type
let transformedData = [];
let transformedData: any[] = [];
for (let index in data) {
let date = data[index];
transformedData.push(ObjectSerializer.deserialize(date, subType));
@@ -406,12 +406,12 @@ export class User {
}
let enumsMap = {
let enumsMap: {[index: string]: any} = {
"Order.StatusEnum": Order.StatusEnum,
"Pet.StatusEnum": Pet.StatusEnum,
}
let typeMap = {
let typeMap: {[index: string]: any} = {
"ApiResponse": ApiResponse,
"Category": Category,
"Order": Order,
@@ -515,7 +515,7 @@ export class PetApi {
}
public setApiKey(key: PetApiApiKeys, value: string) {
this.authentications[PetApiApiKeys[key]].apiKey = value;
(this.authentications as any)[PetApiApiKeys[key]].apiKey = value;
}
set accessToken(token: string) {
@@ -1032,7 +1032,7 @@ export class StoreApi {
}
public setApiKey(key: StoreApiApiKeys, value: string) {
this.authentications[StoreApiApiKeys[key]].apiKey = value;
(this.authentications as any)[StoreApiApiKeys[key]].apiKey = value;
}
set accessToken(token: string) {
@@ -1290,7 +1290,7 @@ export class UserApi {
}
public setApiKey(key: UserApiApiKeys, value: string) {
this.authentications[UserApiApiKeys[key]].apiKey = value;
(this.authentications as any)[UserApiApiKeys[key]].apiKey = value;
}
set accessToken(token: string) {

View File

@@ -1,14 +1,15 @@
"use strict";
var api = require('./api');
var fs = require('fs');
Object.defineProperty(exports, "__esModule", { value: true });
const api = require("./api");
const fs = require("fs");
function deepCheck(objectA, objectB) {
var a = objectA;
var b = objectB;
var isString = (typeof a === "string" && typeof b === "string");
var isBool = (typeof a === "boolean" && typeof b === "boolean");
var isNumber = (typeof a === "number" && typeof b === "number");
let a = objectA;
let b = objectB;
let isString = (typeof a === "string" && typeof b === "string");
let isBool = (typeof a === "boolean" && typeof b === "boolean");
let isNumber = (typeof a === "number" && typeof b === "number");
if (a instanceof Array && b instanceof Array) {
for (var i = 0; i < a.length; i++) {
for (let i = 0; i < a.length; i++) {
if (!deepCheck(a[i], b[i])) {
return false;
}
@@ -19,7 +20,7 @@ function deepCheck(objectA, objectB) {
return a === b;
}
else if (typeof a === "object" && typeof b === "object") {
for (var key in a) {
for (let key in a) {
if (!deepCheck(a[key], b[key])) {
return false;
}
@@ -66,8 +67,8 @@ var deserializedPet = objectSerializer.deserialize(serializedPet, "Pet");
var petType = deserializedPet instanceof rewiredApi.Pet;
var tagType1 = deserializedPet.tags[0] instanceof rewiredApi.Tag;
var categoryType = deserializedPet.category instanceof rewiredApi.Category;
var checks = {};
for (var key in deserializedPet) {
let checks = {};
for (let key in deserializedPet) {
checks[key] = {};
checks[key]["isCorrect"] = deepCheck(deserializedPet[key], serializedPet[key]);
checks[key]["is"] = deserializedPet[key];
@@ -80,8 +81,8 @@ if (!correctTypes) {
console.log("TagType1 correct: ", tagType1);
console.log("CategoryType correct: ", categoryType);
}
for (var key in checks) {
var check = checks[key];
for (let key in checks) {
let check = checks[key];
if (!check["isCorrect"]) {
exitCode = 1;
console.log(key, " incorrect ", "\nis:\n ", check["is"], "\nshould:\n ", check["should"]);
@@ -98,29 +99,27 @@ if (!deepCheck(reserializedData, serializedPet)) {
exitCode = 1;
console.log("Reserialized Data incorrect! \nis:\n ", reserializedData, "\nshould:\n ", serializedPet);
}
pet.category = undefined;
pet.status = undefined;
petApi.addPet(pet)
.then(function (res) {
.then((res) => {
var newPet = res.body;
petId = newPet.id;
console.log("Created pet with ID " + petId);
console.log(`Created pet with ID ${petId}`);
newPet.status = api.Pet.StatusEnum.Available;
return petApi.updatePet(newPet);
})
.then(function (res) {
.then((res) => {
console.log('Updated pet using POST body');
return petApi.updatePetWithForm(petId, undefined, "pending");
})
.then(function (res) {
.then((res) => {
console.log('Updated pet using POST form');
return petApi.uploadFile(petId, undefined, fs.readFileSync('sample.png'));
})
.then(function (res) {
.then((res) => {
console.log('Uploaded image');
return petApi.getPetById(petId);
})
.then(function (res) {
.then((res) => {
console.log('Got pet by ID: ' + JSON.stringify(res.body));
console.log("EnumValue: ", api.Pet.StatusEnum.Pending);
console.log("Typeof EnumValue:", typeof api.Pet.StatusEnum.Pending);
@@ -129,14 +128,14 @@ petApi.addPet(pet)
throw new Error("Unexpected pet status");
}
})
.catch(function (err) {
.catch((err) => {
console.error(err);
exitCode = 1;
})
.then(function () {
.then(() => {
return petApi.deletePet(petId);
})
.then(function (res) {
.then((res) => {
console.log('Deleted pet');
process.exit(exitCode);
});

File diff suppressed because one or more lines are too long

View File

@@ -116,10 +116,6 @@ if (!deepCheck(reserializedData, serializedPet)) {
"\nshould:\n ", serializedPet);
}
// category and status are not used in the tests below.
pet.category = undefined;
pet.status = undefined;
// Test various API calls to the petstore
petApi.addPet(pet)
.then((res) => {

View File

@@ -36,7 +36,7 @@ git_remote=`git remote`
if [ "$git_remote" = "" ]; then # git remote not defined
if [ "$GIT_TOKEN" = "" ]; then
echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git crediential in your environment."
echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git credential in your environment."
git remote add origin https://github.com/${git_user_id}/${git_repo_id}.git
else
git remote add origin https://${git_user_id}:${GIT_TOKEN}@github.com/${git_user_id}/${git_repo_id}.git

File diff suppressed because it is too large Load Diff

View File

@@ -5,21 +5,22 @@
"repository": "GIT_USER_ID/GIT_REPO_ID",
"main": "api.js",
"scripts": {
"postinstall": "typings install",
"clean": "rm -Rf node_modules/ typings/ *.js",
"clean": "rm -Rf node_modules/ *.js",
"build": "tsc",
"test": "npm run build && node client.js"
},
"author": "Swagger Codegen Contributors",
"license": "Unlicense",
"dependencies": {
"bluebird": "^3.3.5",
"request": "^2.72.0",
"@types/bluebird": "*",
"@types/request": "*",
"@types/rewire": "^2.5.28",
"bluebird": "^3.5.0",
"request": "^2.81.0",
"rewire": "^2.5.2"
},
"devDependencies": {
"typescript": "^1.8.10",
"typings": "^0.8.1"
"typescript": "^2.4.2"
},
"publishConfig": {
"registry": "https://skimdb.npmjs.com/registry"

View File

@@ -3,17 +3,17 @@
"module": "commonjs",
"noImplicitAny": false,
"suppressImplicitAnyIndexErrors": true,
"target": "ES5",
"target": "ES6",
"strict": true,
"moduleResolution": "node",
"removeComments": true,
"sourceMap": true,
"noLib": false,
"declaration": true
"declaration": true,
"lib": ["dom", "es6", "es5", "dom.iterable", "scripthost"]
},
"exclude": [
"node_modules",
"typings/browser",
"typings/browser.d.ts"
"node_modules"
]
}

View File

@@ -1,10 +0,0 @@
{
"ambientDependencies": {
"core-js": "registry:dt/core-js#0.0.0+20160317120654",
"node": "registry:dt/node#4.0.0+20160423143914"
},
"dependencies": {
"bluebird": "registry:npm/bluebird#3.3.4+20160515010139",
"request": "registry:npm/request#2.69.0+20160304121250"
}
}