[Solved] How to push a string in typescript file? [closed]


The Channel class is only being used for type checking as far as I can tell.

Channel.ts

export class Channel {
  name: string;
}

Items.ts

import { Channel } from './Channel';

const items: Channel[] = []; // initialize to empty array
const test: string[] = ["one", "two", "three"];

// because 'test' is an array of strings we need to convert each item
// to be a Channel

const channels = test.map(t => { return { name: t } as Channel }); // the 'as Channel' part is only for type checking

// assign 'channels' to 'test'
test.push(...channels);

Here’s a working example: http://codepen.io/kenhowardpdx/pen/dNLeoJ?editors=0012

0

solved How to push a string in typescript file? [closed]