-
Notifications
You must be signed in to change notification settings - Fork 428
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
targets and typescript #121
Comments
According to https://discourse.stimulusjs.org/t/syntax-error-when-using-targets/23/8 this is not (yet?) possible, instead you’d have to declare each target explicitly. |
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:
|
I'm not sure how easy/hard this would be to do, but it looks like a similar problem to |
FYI: If you use @sunnyrjuneja 's sulotion, you will need this config in tsconfig file, otherwise it will raise an error: "strictPropertyInitialization":false |
@NaiveCAI This is my tsconfig: {
"compilerOptions": {
"declaration": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": ["es6", "dom"],
"module": "es6",
"moduleResolution": "node",
"sourceMap": true,
"target": "es5"
},
"exclude": [
"**/*.spec.ts",
"node_modules",
"vendor",
"public"
],
"compileOnSave": false
} |
You can use an exclamation point to bypass the strict initialization check: class extends Controller {
static targets = [ "name" ]
readonly nameTarget!: Element
readonly nameTargets!: Element[]
readonly hasNameTargets!: boolean
} |
I've been trying to use the approach listed here but I've come across an issue. Using syntax such as class extends Controller {
static targets = [ "name" ]
readonly nameTarget!: Element
readonly nameTargets!: Element[]
readonly hasNameTargets!: boolean
} This gets compiled down to: _this.nameTarget = void 0;
_this.nameTargets = void 0;
_this.hasNameTarget = void 0; And an error appears in the console:
Pausing the debugger at this point, inspecting
EDIT: on further investigation it appears that this is the behaviour of the Related: babel/babel#7644 I'll open a new issue. |
The application will work with Typescript by default. Be aware of how it works with Stimulusjs hotwired/stimulus#121
Hi 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.
The Stimulus documentation says:
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.
The text was updated successfully, but these errors were encountered: