From 224dfeff2cfdc01bdf9a4ef3c407245a91ddc563 Mon Sep 17 00:00:00 2001 From: "francois.grand" <francois.grand@irstea.fr> Date: Mon, 3 Jul 2017 11:14:12 +0200 Subject: [PATCH] Modifs pour pouvoir compiler avec noImplicitAny=true --- src/base.ts | 3 ++- src/cond_distri.ts | 2 +- src/dichotomie.ts | 10 ++++----- src/lechaptcalmon.ts | 2 +- src/param.ts | 13 ++++++++--- src/section/hauteur.ts | 16 +++++++------- src/section/log.ts | 36 +++++++++++++++---------------- src/section/newton.ts | 8 +++---- src/section/section_circulaire.ts | 2 +- src/section/section_puissance.ts | 2 +- src/section/section_rectang.ts | 2 +- src/section/section_trapez.ts | 2 +- src/section/section_type.ts | 26 +++++++++++----------- tsconfig.json | 4 ++-- 14 files changed, 69 insertions(+), 59 deletions(-) diff --git a/src/base.ts b/src/base.ts index e20284f8..f27633f6 100644 --- a/src/base.ts +++ b/src/base.ts @@ -39,7 +39,8 @@ export class Result { private _code: ResultCode; /** Variables intermÊdiaires, flags d'erreur */ - public extraVar: {}; + // public extraVar: {}; + public extraVar: { [key: string]: any }; constructor(v: number, c: ResultCode = ResultCode.OK) { this._vCalc = v diff --git a/src/cond_distri.ts b/src/cond_distri.ts index 8eaf87c7..669088aa 100644 --- a/src/cond_distri.ts +++ b/src/cond_distri.ts @@ -21,7 +21,7 @@ export class ConduiteDistribParams implements IParamsEquation { /** ViscositÊ dynamique nu */ private _Nu: ParamDefinition; - constructor(rQ, rD, rJ, rLg, rNu) { + constructor(rQ: number, rD: number, rJ: number, rLg: number, rNu: number) { this._Q = new ParamDefinition('Q', ParamDomainValue.POS, rQ); this._D = new ParamDefinition('D', ParamDomainValue.POS, rD); this._J = new ParamDefinition('J', ParamDomainValue.POS, rJ); diff --git a/src/dichotomie.ts b/src/dichotomie.ts index 2c49318e..dea0f04b 100644 --- a/src/dichotomie.ts +++ b/src/dichotomie.ts @@ -52,7 +52,7 @@ class Pair { * couple de valeurs ordonnÊes */ class Interval extends Pair { - constructor(bound1, bound2) { + constructor(bound1: number, bound2: number) { super(bound1, bound2); } @@ -84,13 +84,13 @@ class Interval extends Pair { } class SearchInterval extends Interval { - private _step; + private _step: number; private _dicho: Dichotomie; private _targets: Pair; - constructor(d: Dichotomie, min, max, s) { + constructor(d: Dichotomie, min: number, max: number, s: number) { super(min, max); if (s == 0) throw new RangeError("SearchInterval : invalid null step"); @@ -390,7 +390,7 @@ export class Dichotomie extends Debug { // la valeur cible de la fonction est elle trouvable ? - let aps = this.nub.getFirstAnalyticalParameter().symbol; + let aps: string = this.nub.getFirstAnalyticalParameter().symbol; let m; let res: Result; @@ -451,7 +451,7 @@ export class Dichotomie extends Debug { * @param Ymin valeur de la fonction pour Xmin * @param Ymax valeur de la fonction pour Xmax */ - private dichoSearch(Ytarg: number, rTol: number, Xmin: number, Xmax: number, Ymin: number, Ymax: number) { + private dichoSearch(Ytarg: number, rTol: number, Xmin: number, Xmax: number, Ymin: number, Ymax: number): Result { let Xmid = (Xmin + Xmax) / 2; if (Math.abs(Xmin - Xmax) <= rTol) diff --git a/src/lechaptcalmon.ts b/src/lechaptcalmon.ts index 9edb0a26..3ef2b351 100644 --- a/src/lechaptcalmon.ts +++ b/src/lechaptcalmon.ts @@ -27,7 +27,7 @@ export class LechaptCalmonParams implements IParamsEquation { /** Paramètre de rugositÊ N */ private _N: ParamDefinition; - constructor(rQ, rD, rJ, rLg, rL, rM, rN) { + constructor(rQ: number, rD: number, rJ: number, rLg: number, rL: number, rM: number, rN: number) { this._Q = new ParamDefinition('Q', ParamDomainValue.POS, rQ); this._D = new ParamDefinition('D', ParamDomainValue.POS, rD); this._J = new ParamDefinition('J', ParamDomainValue.POS, rJ); diff --git a/src/param.ts b/src/param.ts index 601741b9..859273a8 100644 --- a/src/param.ts +++ b/src/param.ts @@ -45,7 +45,7 @@ export class ParamDomain { this._maxValue = max; } - private checkValue(val, min, max) { + private checkValue(val: number, min: number, max: number) { switch (val) { case ParamDomainValue.INTERVAL: if (min == undefined || max == undefined || min > max) @@ -272,7 +272,14 @@ export class ParamDefinition { * liste des paramètres d'une Êquation */ export interface IParamsEquation { - // [key: string]: number; // map : array of ParamDefinition with string keys + /* + * [key: string]: any + * nÊcessaire pour pouvoir indexer les ParamDefinition des classes qui implÊmentent IParamsEquation + * cad faire <instance>[<chaine>] et rÊcupÊrer un ParamDefinition + * (et Êviter le message 'Element implicitly has an 'any' type because type 'IParamsEquation' has no index signature.' + * lorsqu'on compile avec "noImplicitAny": true) + */ + [key: string]: any; } /** @@ -281,7 +288,7 @@ export interface IParamsEquation { export abstract class ComputeNode extends Debug { protected _prms: IParamsEquation; - protected abstract setParametersCalculability(); + protected abstract setParametersCalculability(): void; constructor(prms: IParamsEquation, dbg: boolean = false) { super(dbg); diff --git a/src/section/hauteur.ts b/src/section/hauteur.ts index 84e313dd..49e048d9 100644 --- a/src/section/hauteur.ts +++ b/src/section/hauteur.ts @@ -25,7 +25,7 @@ export class cHautCritique extends acNewton { * Calcul de la fonction dont on cherche le zÊro * @param rX Variable dont dÊpend la fonction */ - CalcFn(rX) { + CalcFn(rX: number) { // Calcul de la fonction if (this.Sn.Calc("S", rX) != 0) return (Math.pow(this.Sn.prms.Q.v, 2) * this.Sn.Calc("B", rX) / Math.pow(this.Sn.Calc("S", rX), 3) / cParamsCanal.G - 1); @@ -37,7 +37,7 @@ export class cHautCritique extends acNewton { * Calcul analytique de la dÊrivÊe de la fonction dont on cherche le zÊro * @param rX Variable dont dÊpend la fonction */ - CalcDer(rX) { + CalcDer(rX: number) { let S = this.Sn.Calc("S"); if (S != 0) { let B = this.Sn.Calc("B"); @@ -90,7 +90,7 @@ export class cHautNormale extends acNewton { * Calcul de la fonction dont on cherche le zÊro * @param rX Variable dont dÊpend la fonction */ - CalcFn(rX) { + CalcFn(rX: number) { // Calcul de la fonction return (this.Q - this.Ks * Math.pow(this.Sn.Calc("R", rX), 2 / 3) * this.Sn.Calc("S", rX) * Math.sqrt(this.If)); } @@ -99,7 +99,7 @@ export class cHautNormale extends acNewton { * Calcul analytique de la dÊrivÊe de la fonction dont on cherche le zÊro * @param rX Variable dont dÊpend la fonction */ - CalcDer(rX) { + CalcDer(rX: number) { // L'initialisation a ÊtÊ faite lors de l'appel à CalcFn let Der = 2 / 3 * this.Sn.Calc("dR") * Math.pow(this.Sn.Calc("R"), -1 / 3) * this.Sn.Calc("S"); Der = Der + Math.pow(this.Sn.Calc("R"), 2 / 3) * this.Sn.Calc("B"); @@ -148,7 +148,7 @@ export class cHautCorrespondante extends acNewton { * Calcul de la fonction dont on cherche le zÊro * @param rX Variable dont dÊpend la fonction */ - CalcFn(rX) { + CalcFn(rX: number) { // Calcul de la fonction return this.Y - rX + (this.rS2 - Math.pow(this.Sn.Calc("S", rX), -2)) * this.rQ2G; } @@ -157,7 +157,7 @@ export class cHautCorrespondante extends acNewton { * Calcul analytique de la dÊrivÊe de la fonction dont on protected function cherche le zÊro * @param rX Variable dont dÊpend la fonction */ - CalcDer(rX) { + CalcDer(rX: number) { let S = this.Sn.Calc("S"); // L'initialisation a ÊtÊ faite lors de l'appel à CalcFn if (S != 0) @@ -199,7 +199,7 @@ export class cHautConjuguee extends acNewton { * Calcul de la fonction dont on cherche le zÊro * @param rX Variable dont dÊpend la fonction */ - CalcFn(rX) { + CalcFn(rX: number) { // RÊinitialisation des paramètres hydrauliques de oSn avec l'appel this->oSn->Calc("S',rX) if (this.rS > 0 && this.Sn.Calc("S", rX) > 0) { let Fn = this.rQ2 * (1 / this.rS - 1 / this.Sn.Calc("S")); @@ -213,7 +213,7 @@ export class cHautConjuguee extends acNewton { * Calcul analytique de la dÊrivÊe de la fonction dont on cherche le zÊro * @param rX Variable dont dÊpend la fonction */ - CalcDer(rX) { + CalcDer(rX: number) { let S = this.Sn.Calc("S"); // L'initialisation a ÊtÊ faite lors de l'appel à CalcFn if (this.rS > 0 && S > 0) { diff --git a/src/section/log.ts b/src/section/log.ts index a86d67c1..abaf9c7f 100644 --- a/src/section/log.ts +++ b/src/section/log.ts @@ -1,23 +1,23 @@ export class cLog { - - public txt; - - constructor() { - this.txt = ''; - } - - Add(sTxt,bErr=false) { + + public txt: string; + + constructor() { + this.txt = ''; + } + + Add(sTxt: string, bErr = false) { // peut on mettre des balises ? - this.txt += '<li'; - if(bErr) {this.txt += ' class="hyd_erreur"';} - this.txt += '>'+sTxt+'</li>'; - } - Result() { - if(this.txt!='') { - return this.txt; - } else { - return ''; - } + this.txt += '<li'; + if (bErr) { this.txt += ' class="hyd_erreur"'; } + this.txt += '>' + sTxt + '</li>'; + } + Result() { + if (this.txt != '') { + return this.txt; + } else { + return ''; } + } } \ No newline at end of file diff --git a/src/section/newton.ts b/src/section/newton.ts index 35626027..7ae0e134 100644 --- a/src/section/newton.ts +++ b/src/section/newton.ts @@ -26,14 +26,14 @@ export abstract class acNewton extends Debug { * @param rX x * @return Calcul de la fonction */ - abstract CalcFn(rX); + abstract CalcFn(rX: number): number; /** * Calcul de la dÊrivÊe f'(x) (peut ÃĒtre redÊfini pour calcul analytique) * @param rX x * @return Calcul de la fonction */ - protected CalcDer(x) { + protected CalcDer(x: number) { return (this.CalcFn(x + this.Dx) - this.CalcFn(x - this.Dx)) / (2 * this.Dx); } @@ -42,7 +42,7 @@ export abstract class acNewton extends Debug { * @param rFn x * @return True si Êgal, False sinon */ - private FuzzyEqual(rFn) { + private FuzzyEqual(rFn: number) { return (Math.abs(rFn) < this.rTol); } @@ -52,7 +52,7 @@ export abstract class acNewton extends Debug { * @param rX x * @return Solution du zÊro de la fonction */ - public Newton(rX) { + public Newton(rX: number): number { this.iCpt++; var rFn = this.CalcFn(rX); if (this.FuzzyEqual(rFn) || this.iCpt >= this.iCptMax) diff --git a/src/section/section_circulaire.ts b/src/section/section_circulaire.ts index ba1b26d7..995b70c9 100644 --- a/src/section/section_circulaire.ts +++ b/src/section/section_circulaire.ts @@ -5,7 +5,7 @@ import { cLog } from "./log"; export class ParamsSectionCirc extends ParamsSection { private _D: ParamDefinition; // Diamètre du cercle - constructor(rD, rY, rKs, rQ, rIf, rPrec, rYB, rYCL = undefined, rDx = undefined, rLong = undefined) { + constructor(rD: number, rY: number, rKs: number, rQ: number, rIf: number, rPrec: number, rYB: number, rYCL: number = undefined, rDx: number = undefined, rLong: number = undefined) { super(rY, undefined, rKs, rQ, rIf, rPrec, rYB, rYCL); this._D = new ParamDefinition('D', ParamDomainValue.POS, rD); } diff --git a/src/section/section_puissance.ts b/src/section/section_puissance.ts index 95ea2c37..81f972a8 100644 --- a/src/section/section_puissance.ts +++ b/src/section/section_puissance.ts @@ -9,7 +9,7 @@ import { cLog } from "./log"; export class ParamsSectionPuiss extends ParamsSection { private _k: ParamDefinition; // Coefficient de forme compris entre 0 et 1 - constructor(rk, rY, rLargeurBerge, rKs, rQ, rIf, rPrec, rYB, rYCL = 0, rDx = 0, rLong = 0) { + constructor(rk: number, rY: number, rLargeurBerge: number, rKs: number, rQ: number, rIf: number, rPrec: number, rYB: number, rYCL: number = 0, rDx: number = 0, rLong: number = 0) { super(rY, rLargeurBerge, rKs, rQ, rIf, rPrec, rYB, rYCL); this._k = new ParamDefinition('k', new ParamDomain(ParamDomainValue.INTERVAL, 0, 1), rk); } diff --git a/src/section/section_rectang.ts b/src/section/section_rectang.ts index b1dde765..537b62bd 100644 --- a/src/section/section_rectang.ts +++ b/src/section/section_rectang.ts @@ -3,7 +3,7 @@ import { acSection, ParamsSection } from "./section_type"; import { cLog } from "./log"; export class ParamsSectionRectang extends ParamsSection { - constructor(rY, rLargeurFond, rKs, rQ, rIf, rPrec, rYB, rYCL = 0, rDx = 0, rLong = 0) { + constructor(rY: number, rLargeurFond: number, rKs: number, rQ: number, rIf: number, rPrec: number, rYB: number, rYCL: number = 0, rDx: number = 0, rLong: number = 0) { super(rY, rLargeurFond, // LargeurBerge=LargeurFond rKs, rQ, rIf, rPrec, rYB, rYCL); diff --git a/src/section/section_trapez.ts b/src/section/section_trapez.ts index f6a20769..23d60825 100644 --- a/src/section/section_trapez.ts +++ b/src/section/section_trapez.ts @@ -7,7 +7,7 @@ export class ParamsSectionTrapez extends ParamsSection { private _LargeurFond: ParamDefinition; // Largeur au fond private _Fruit: ParamDefinition; // Fruit des berges - constructor(rLargeurFond, rFruit, rY, rKs, rQ, rIf, rPrec, rYB, rYCL = 0, rDx = 0, rLong = 0) { + constructor(rLargeurFond: number, rFruit: number, rY: number, rKs: number, rQ: number, rIf: number, rPrec: number, rYB: number, rYCL: number = 0, rDx: number = 0, rLong: number = 0) { super(rY, undefined, rKs, rQ, rIf, rPrec, rYB, rYCL); this._LargeurFond = new ParamDefinition('LargeurFond', ParamDomainValue.POS_NULL, rLargeurFond); this._Fruit = new ParamDefinition('Fruit', ParamDomainValue.POS_NULL, rFruit); diff --git a/src/section/section_type.ts b/src/section/section_type.ts index 63a911ef..19e287e7 100644 --- a/src/section/section_type.ts +++ b/src/section/section_type.ts @@ -20,7 +20,7 @@ export abstract class cParamsCanal implements IParamsEquation { private _Long: ParamDefinition; // Longueur du bief // public Resolution; /// MÊthode de rÊsolution "Euler" ou "RK4" - constructor(rKs, rQ, rIf, rPrec, rYB, rYCL = undefined, rDx = undefined, rLong = undefined) //, sResolution = '') { + constructor(rKs: number, rQ: number, rIf: number, rPrec: number, rYB: number, rYCL: number = undefined, rDx: number = undefined, rLong: number = undefined) //, sResolution = '') { { //this.prms.Resolution = sResolution; this._Ks = new ParamDefinition('Ks', ParamDomainValue.POS, rKs); @@ -103,7 +103,7 @@ export abstract class ParamsSection extends cParamsCanal { private _Y: ParamDefinition; // Tirant d'eau private _LargeurBerge: ParamDefinition; // largeur au dÊbordement - constructor(rY, rLargeurBerge, rKs, rQ, rIf, rPrec, rYB, rYCL = undefined, rDx = undefined, rLong = undefined) { + constructor(rY: number, rLargeurBerge: number, rKs: number, rQ: number, rIf: number, rPrec: number, rYB: number, rYCL: number = undefined, rDx: number = undefined, rLong: number = undefined) { super(rKs, rQ, rIf, rPrec, rYB, rYCL, rDx, rLong); this._Y = new ParamDefinition('Y', ParamDomainValue.POS_NULL, rY); @@ -130,8 +130,10 @@ export abstract class ParamsSection extends cParamsCanal { * Comprend les formules pour la section rectangulaire pour gÊrer les dÊbordements */ export abstract class acSection extends ComputeNode { + [key: string]: any; // pour pouvoir faire this['methode](); + public HautCritique: number; /// Tirant d'eau critique - public HautNormale; /// Tirant d'eau normal + public HautNormale: number; /// Tirant d'eau normal protected oLog: cLog; /// Pour l'affichage du journal de calcul /** @@ -153,9 +155,9 @@ export abstract class acSection extends ComputeNode { * - dR : la dÊrivÊe de R par rapport Y * - dB : la dÊrivÊe de B par rapport Y */ - private arCalc = {}; - protected arCalcGeo = {}; /// DonnÊes ne dÊpendant pas de la cote de l'eau - private Y_old; /// MÊmorisation du tirant d'eau pour calcul intermÊdiaire + private arCalc: { [key: string]: number } = {}; + protected arCalcGeo: { [key: string]: number } = {}; /// DonnÊes ne dÊpendant pas de la cote de l'eau + private Y_old: number; /// MÊmorisation du tirant d'eau pour calcul intermÊdiaire private Calc_old = {}; /// MÊmorisation des donnÊes hydrauliques pour calcul intermÊdiaire /** @@ -223,7 +225,7 @@ export abstract class acSection extends ComputeNode { * MÊmorise les donnÊes hydraulique en cours ou les restitue * @param bMem true pour mÊmorisation, false pour restitution */ - private Swap(bMem) { + private Swap(bMem: boolean) { if (bMem) { this.debug("save Y=" + this.prms.Y.toString()); this.Y_old = this.prms.Y.uncheckedValue; @@ -268,7 +270,7 @@ export abstract class acSection extends ComputeNode { une valeur bien dÊfinie !!!!! */ - let res = this[methode](); + let res: number = this[methode](); this.arCalc[sDonnee] = res; break; } @@ -287,7 +289,7 @@ export abstract class acSection extends ComputeNode { * @param sDonnee ClÊ de la donnÊe à calculer (voir this->arCalcGeo) * @return la donnÊe calculÊe */ - CalcGeo(sDonnee): number { + CalcGeo(sDonnee: string): number { this.debug("in CalcGeo(" + sDonnee + ") old " + sDonnee + "=" + this.arCalcGeo[sDonnee]); this.debug("this.Y=" + this.prms.Y.toString()); @@ -470,7 +472,7 @@ export abstract class acSection extends ComputeNode { /** * Calcul de dy/dx */ - Calc_dYdX(Y): number { + Calc_dYdX(Y: number): number { // L'appel à Calc("J') avec Y en paramètre rÊinitialise toutes les donnÊes dÊpendantes de la ligne d'eau return - (this.prms.If.v - this.Calc("J", Y) / (1 - Math.pow(this.Calc("Fr", Y), 2))); } @@ -479,7 +481,7 @@ export abstract class acSection extends ComputeNode { * Calcul du point suivant de la courbe de remous par la mÊthode Euler explicite. * @return Tirant d'eau */ - Calc_Y_Euler(Y): number { + Calc_Y_Euler(Y: number): number { // L'appel à Calc("J') avec Y en paramètre rÊinitialise toutes les donnÊes dÊpendantes de la ligne d'eau var Y2 = Y + this.prms.Dx.v * this.Calc_dYdX(Y); if (XOR(this.prms.Dx.v > 0, !(Y2 < this.HautCritique))) @@ -492,7 +494,7 @@ export abstract class acSection extends ComputeNode { * Calcul du point suivant de la courbe de remous par la mÊthode RK4. * @return Tirant d'eau */ - Calc_Y_RK4(Y): number { + Calc_Y_RK4(Y: number): number { // L'appel à Calc("J') avec Y en paramètre rÊinitialise toutes les donnÊes dÊpendantes de la ligne d'eau var Dx = this.prms.Dx.v; var k1 = this.Calc_dYdX(Y); diff --git a/tsconfig.json b/tsconfig.json index 63b55c59..f91d40af 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,10 +3,10 @@ "target": "es5", "module": "commonjs", "outDir": "./build", - "noImplicitAny": false, + "noImplicitAny": true, "sourceMap": true }, "exclude": [ "node_modules" ] -} \ No newline at end of file +} -- GitLab