<!doctype html><html> <head> <meta charset="UTF-8"> <title>Exécution de source.ts</title> </head> <body> <h1>Conversion de script TypeScript vers JS et rendu</h1> <script type="text/javascript">/* Types basiques */var PI = Math.PI;var title = "Démonstration TypeScript";var isChecked;/* Tableaux */var languages = ["JavaScript", "TypeScript", "Babel", "JSX"];var randoms;/* Enumérations */var translates;(function (translates) { translates[translates["FR"] = 0] = "FR"; translates[translates["EN"] = 1] = "EN"; translates[translates["DE"] = 2] = "DE"; translates[translates["ES"] = 3] = "ES";})(translates || (translates = {}));;console.log(translates);/* Type indéfini */var iDontKnow;/* Typage de fonction */function surfaceCercle(rayon) { return PI * rayon * rayon;}console.log(surfaceCercle(10));function surfaceRectangle(rect) { return rect.largeur * rect.longueur;}var r1 = { largeur: 5, longueur: 10 };console.log(surfaceRectangle(r1));var b1 = { largeur: 5, longueur: 10, hauteur: 2};console.log(b1);/* Définition de la classe Circle donnant accès aux calculs de surface et volume */var Circle = /** @class */ (function () { function Circle(rayon) { this.p = 16; /* Précision : nombre de chiffres après la virgule */ this.name2D = "Cercle"; this.name3D = "Sphere"; this.r = rayon; } Circle.prototype.surface2D = function () { return parseFloat((Math.PI * this.r * this.r).toFixed(this.p)); }; Circle.prototype.surface3D = function () { return parseFloat((4 * Math.PI * this.r * this.r).toFixed(this.p)); }; Circle.prototype.perimeter = function () { return parseFloat((2 * Math.PI * this.r).toFixed(this.p)); }; Circle.prototype.volume = function () { return parseFloat((4 / 3 * Math.PI * this.r * this.r * this.r).toFixed(this.p)); }; Circle.prototype.getPrecision = function () { return this.p; }; Circle.prototype.setPrecision = function (precision) { if (precision < 0) { precision = 0; } if (precision > 16) { precision = 16; } this.p = precision; }; Circle.prototype.toString = function () { return "Rayon=" + this.r + " (précision=" + this.p + ") n " + this.name2D.toUpperCase() + " : Périmètre=" + this.perimeter() + " Surface=" + this.surface2D() + " n " + this.name3D.toUpperCase() + " : Surface=" + this.surface3D() + " Volume=" + this.volume(); }; return Circle;}());var monCercle = new Circle(10);monCercle.setPrecision(2);console.log(monCercle.toString()); </script> </body></html>