Params in TypeScript
- methodname(... variable_name : type[]){}
- MyMethos(... params : number[]){}
What's param do
params .ts
- class Test {
- Method1(value: string) { // only for single string value
- alert("" + value);
- }
- Method2(...params: number[]) { // Params but number type
- // var total=0;
- for (var i = 0; i < params.length; i++) {
- alert("" + params[i]);
- }
- }
- Method3(...params: any[]) { // params with any type
- // var total=0;
- for (var i = 0; i < params.length; i++) {
- alert("" + params[i]);
- }
- }
- }
- window.onload = () => {
- var data = new Test();
- data.Method1("Mcn Solution");
- data.Method2(1, 2, 3, 4, 5, 6);
- data.Method3(1, "Mcn", 3.3, 'c');
- }
default.html
- <!DOCTYPEhtml>
- <htmllang="en"
- xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <metacharset="utf-8"/>
- <title>Params in TypeScript</title>
- <linkrel="stylesheet"href="app.css"type="text/css"/>
- <scriptsrc="app.js">
- </script>
- </head>
- <body>
- <h1>Params in TypeScript</h1>
- <divid="content"/>
- </body>
- </html>
app.js
- var Test = (function() {
- function Test() {}
- Test.prototype.Method1 = function(value) {
- alert("" + value);
- };
- Test.prototype.Method2 = function() {
- var params = [];
- for (var _i = 0; _i < (arguments.length - 0); _i++) {
- params[_i] = arguments[_i + 0];
- }
- for (var i = 0; i < params.length; i++) {
- alert("" + params[i]);
- }
- };
- Test.prototype.Method3 = function() {
- var params = [];
- for (var _i = 0; _i < (arguments.length - 0); _i++) {
- params[_i] = arguments[_i + 0];
- }
- for (var i = 0; i < params.length; i++) {
- alert("" + params[i]);
- }
- };
- return Test;
- })();
- window.onload = function() {
- var data = new Test();
- data.Method1("Mcn Solution");
- data.Method2(1, 2, 3, 4, 5, 6);
- data.Method3(1, "Mcn", 3.3, 'c');
- };
Step 4
Output of Method1
It takes only a single string value (simple function):


It can take n number of arguments and accepts all types.


Fero ChvostaľPosted Jan 7, 2021, 4:46 PM
Seems like someone stole the article from you: https://morioh.com/p/fce2b1e392c3
Peter WhitePosted Dec 11, 2012, 3:27 AM
Many people prefer to buy the <a href="http://www.ywcart.com/nike-air-jordans-c-47.html">Cheap Nike Air Jordan</a> online because there are number of benefits that they are likely to enjoy.