question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Typescript constructor access modifiers are not working in dev mode

See original GitHub issue

When creating a class in typescript with access modifiers in constructor, the constructor parameters are not converted into class properties. The following example will not work correctly export class Test { constructor(public foo: string) {} } console.log(new Test("bar"));

Steps to reproduce:

  • create a new project using the cli command: preact create typescript projectName
  • create the class with access modifiers in constructor
  • run the project in dev mode using: npm run dev

Note: this issue is not reproducible using the build command, it is only reproducible in dev (prect watch) mode.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
ratoi-crystycommented, Jun 22, 2020

Tested using a local linked version of the CLI, and indeed it works. Thanks for your support.

0reactions
rschristiancommented, Jun 22, 2020

Glad to hear it. Sorry, I know that’s not a brilliant solution, but it’ll be an option until the next CLI release. Alternatively you can try an older CLI version, but no idea if that’ll work.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular:Why is constructor parameters without access ...
Giving an access specifier to a function parameter is none sense. In TypeScript, you can do this anyway to the constructor, and the...
Read more >
Constructors and Access modifiers in TypeScript/Angular
Note: In TypeScript we can have only one constructor method into the class — but we can have optional parameters in constructor —...
Read more >
Parameter decorator with modifier in the constructor does not ...
If at least one modifier is missing, it works fine. Input code // not work class MyClass { constructor(@Inject() readonly param1: Injected) ...
Read more >
Access modifiers and constructor in TypeScript | by Mrunali Patil
Access modifiers is used to achieve important feature of Object Oriented Programming, this feature is known as data hiding.
Read more >
How to add Access Modifiers with Constructor Parameters in ...
Learn to use Typescript best and essential feature of adding Access Modifiers in Constructor Parameters for initialization with example.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found