targets and typescript
See original GitHub issueHi there!
Thanks for open sourcing stimulus. It’s been a real joy to use so far and I’m excited to really dig deep into it.
I noticed that the default example creates a typescript compiler error.
import { Controller } from "stimulus"
export default class extends Controller {
static targets = [ "output" ]
connect() {
this.outputTarget.textContent = 'Hello, Stimulus!' //[ts] Property 'outputTarget' does not exist on type 'default'.
}
}
The Stimulus documentation says:
When Stimulus loads your controller class, it looks for target name strings in a static array called targets. For each target name in the array, Stimulus adds three new properties to your controller. Here, our “source” target name becomes the following properties:
- this.sourceTarget evaluates to the first source target in your controller’s scope. If there is no source target, accessing the property throws an error.
- this.sourceTargets evaluates to an array of all source targets in the controller’s scope.
- this.hasSourceTarget evaluates to true if there is a source target or false if not.
Is there anyway to let Typescript know about this.sourceTarget, this.sourceTargets, and this.hasSourceTarget? I thought this might be alleviate since the library is written in Typescript.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:3
- Comments:7 (3 by maintainers)
Top Results From Across the Web
TSConfig Option: target - TypeScript
The target setting changes which JS features are downleveled and which are left intact. For example, an arrow function () => this will...
Read more >What is target in tsconfig.json for? - Stack Overflow
I am quite new to Typescript. What does Target ... target signifies which target of JavaScript should be emitted from the given TypeScript....
Read more >Typescript - selecting proper target version - Dancing with CRM
Learn why you should choose proper target version in your tsconfig file and how it boost your code.
Read more >Easy TypeScript: A Quick Guide to the target Option
The target option is configurable in your tsconfig.json or on the command-line via the --target flag. It refers to the JavaScript target that...
Read more >TypeScript target | webhint documentation
typescript -config/target takes into account your webhint 's browserslist configuration and warns you if your target ( es3 , es2015 , etc.) is...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thank you @docstun! I see that someone has the same problem as me. I should have checked the forum too 😃. Since the maintainers are aware of the issue and there is a workaround, I’ll close this issue.
Workaround for future searchers:
You can use an exclamation point to bypass the strict initialization check: