bobbyrne01
bobbyrne01

Reputation: 6735

Property does not exist on type using typescript

App.ts

import { $, WebElement } from 'protractor';
export class App {

  public appName: WebElement;

  constructor() {
    this.appName = $('#appName');
  }
}

app.e2e.test.ts

import { browser, $ } from 'protractor';
import { App } from '../pageobjects/App'
const BASE_URL = 'http://localhost:1344';

describe('App', () => {

  beforeEach(() => {
    browser.get(BASE_URL);
  });

  it('should load the Sites UI homepage', () => {
    console.log(App.appName);
  });
});

Any idea why I cannot access the properties defined in App.ts?

Error:

> tsc -p tsconfig.test.json && protractor dist/protractor.config.js

test/e2e/app.e2e.test.ts(15,28): error TS2339: Property 'appName' does not exist on type 'typeof App'.

Upvotes: 1

Views: 1700

Answers (1)

Yonatan Lilling
Yonatan Lilling

Reputation: 298

in your exception its pretty clear what's wrong:

property 'appName' does not exist on type 'typeof App'.

for this to work you need the declare a new instance of App like so:

describe('App', () => {
  app: App;

  beforeEach(() => {
    browser.get(BASE_URL);
    app = new App();
  });

  it('should load the Sites UI homepage', () => {
    console.log(app.appName);
  });
});

Upvotes: 2

Related Questions