0

I have this simple Typescript class

export class Hello{ myname: string = 'Scott'; sayHello() { console.log(this.myname); } } 

From one of my Protractor Typescript files I do this

import { Hello } from './hello'; const hello = new Hello(); hello.sayHello(); 

However this results in a Typescript compilation error:

[11:48:33] E/launcher - Error: TSError: ⨯ Unable to compile TypeScript: projects/cxone-component-showcase/e2e/src/hello.ts(3,14): error TS2339: Property 'myname' does not exist on type 'Hello'. projects/cxone-component-showcase/e2e/src/hello.ts(6,26): error TS2339: Property 'myname' does not exist on type 'Hello'.

I can take the same exact Typescript class and use it the actual Angular app and it works just fine. Do I need to update something in the tsconfig file for the e2e tests? Currently for e2e the config is

{ "extends": "../../../tsconfig.json", "compilerOptions": { "outDir": "../../../out-tsc/e2e", "module": "commonjs", "target": "es5", "types": [ "jasmine", "jasminewd2", "node" ] } } 

Any ideas this is driving me crazy.

1
  • you need to add a constructor , i think :) Commented Oct 25, 2019 at 16:59

1 Answer 1

2

I had these two lines in my protractor config file to allow imports to be loaded from the path attribute specified in the tsconfig file:

require('ts-node/register'); require('tsconfig-paths/register'); 

The require('ts-node/register'); was the issue. Once I removed it the issue went away. Turns out I only needed require('tsconfig-paths/register'); for the paths to work.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.