-
Notifications
You must be signed in to change notification settings - Fork 53
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
Should glint prevent the "noPropertyAccessFromIndexSignature" compiler option being applied to templates? #508
Comments
This is the same issue/request as I had in #196. I agree with everything written and the reasoning behind it. |
The TypeScript compiler error message is also misleading/confusing, because you cannot write it in handlebars as |
I don't think that flag should be enabled by default—it's the only one we set in That kind of check seems much more appropriate in my opinion as a type-aware lint rule.
I don't see that it's any more or less useful applied to templates than it is to scripts.
Accessing fields with
That's absolutely a bug we should fix—thank you for calling it out! |
For what it's worth, my own personal opinion matches; if I recall our discussion at the time we enabled it, the problem was that if you don't have it on in the source types you can end up with things that don't work for consumers. However, that could well be mistaken—either in the assertion itself (I’m not sure how that would be true?) or in my memory! If the assertion that it can make things appear safe in the source types that consumers cannot is wrong, though—and I think it is?—, we should loosen it back up in the default, though. |
From a quick read of the docs, it does look like I tried this out: const zz: Record<string, string> = {};
const x = zz.b; // Error: Property 'b' comes from an index signature, so it must be accessed with ['b'].ts(4111)
const y = zz['b']; // OK
type X = typeof zz.b; // OK (X = string | undefined) From the docs:
So it's pretty clear that this is purely a linter flag that does not affect correctness of the program. It's probably most useful in projects that are not using This is in contrast with the flags I now agree with @dfreeman and @chriskrycho that the default tsconfig should not set If it's a really common case that there are projects that use e.g. For my own use case, I'll go with the option of implementing a trivial import styles from './styles.scss';
const localClass = (klass: string) => this.styles[klass];
<template>
<div class={{localClass "widget-base"}}>
...
</div>
</template> I'll open a separate issue regarding the need to fix the error message so that it suggests |
Ah, one other thing to consider: glint converts property accesses of the form |
@chriskrycho I do remember a conversation like that, but it might have been about I think For
@bwbuchanan can you give examples of cases where you've had to override types because the upstream definitions didn't have those flags enabled? Off the top of my head I can't construct an example of a |
cibernox/ember-basic-dropdown#687 was a good example, although the bug in ember-power-select that had it importing from ember-basic-dropdown's source files instead of its declarations has been fixed (ref #507) Maybe class Superclass {
foobar(): string;
}
class Subclass extends Superclass {
foobar(abc: number): string; // Should be: override foobar(abc: number): string;
} One place that So imagine a component defined in an addon (not built with interface NamedArgs {
foo: string;
bar?: string;
}
class UnintentionallyPickyComponent<{ Args: NamedArgs }> { ... } Then with class Wrapper extends Component<{ Args: { foo: string; bar?: string | undefined; } }> {
<template>
<div class="wrapping-component">
...
<UnintentionallyPickyComponent @foo={{@foo}} @bar={{@bar}}>
</div>
</template>
} TypeScript will error because Unfortunately, TypeScript has no way for a Wrapper-style composition of components is quite common, I think. It's a shame that there's no splattributes syntax for component args. |
The same "explicitly passing
I agree, but/and fundamentally I think most of your argument is best served by introducing "splarguments" in Ember rather than enforcing type rules differently in TS than in templates. I'm going to close this issue out, since the actionable technical change (fixing the error message not to suggest |
@tsconfig/ember/tsconfig.json
specifies"noPropertyAccessFromIndexSignature": true
. And this is probably a good thing.However, I do not think it is useful when applied to templates.
If I don't disable this check in my own
tsconfig.json
, I get errors reported such as:In this case,
styles
is from an imported SCSS file. The values of the record are mangled (globally unique) CSS class names generated by webpack'ssass-loader
/css-loader
.It's used like:
Declared in
global.d.ts
as:Templates accessing properties on a
Record
in this manner is idiomatic ember; writing it as{{get styles "label"}}
is awkward.If glint generated property accesses as
styles['label']
instead ofstyles.label
, that would resolve the errors.Alternatives I considered:
*.scss
asany
instead ofRecord<string, string>
- loses type informationstyles
record, e.g.{{style "label"}}
instead of{{styles.label}}
- adds boilerplate and runtime overhead{{get}}
- verbose and non-idiomaticThe text was updated successfully, but these errors were encountered: