You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Please keep and fill in the line that best applies:
-->
This is a crash
This changed between versions ______ and _______
This is the behavior in every version I tried, and I reviewed the FAQ for entries about everything_
I was unable to test this on prior versions because _______
💻 Code
typeData=Record<string,string>;letx: Data={};x['foo bar baz']='5';x.foo='4';// ^ error // Property 'foo' comes from an index signature, so it must be accessed with ['foo'].(4111)x.foo;// ^ error // Property 'foo' comes from an index signature, so it must be accessed with ['foo'].(4111)
🙁 Actual behavior
the noPropertyAccessFromIndexSignature setting is too aggressive and isn't helpful for objects which use identifier keys
🙂 Expected behavior
I almost want there to be a way to specify that keys can be valid identifiers. It seems that noPropertyAccessFromIndexSignature is designed to protect against/for/adhere-to-correctness the fact that "string" (as used in the Key in Record, above) means, literally, "any string", which could include non-identifiers, such as foo bar baz, or foo.bar -- these can be valid keys on an object, but we don't have a way to express that we can manage different kinds of keys.
Sure, an object, by default, is "anything goes" with its keys, but the type system has no way to narrow a key to an identifier.
If I could somehow say:
typeData=Record<Identifier,string>;
then my problem would be solved, and my example could would provide (non) errors like so:
letx: Data={};x['foo bar baz']='5';// ^ error// Property 'foo bar baz' does not match type Identifier. ( error code )x.foo='4';// no errorx.foo;// no error
The text was updated successfully, but these errors were encountered:
the noPropertyAccessFromIndexSignature setting is too aggressive and isn't helpful for objects which use identifier keys
I'm really confused about what you're asking for. It's already the case that the only time you can write x.foo is when foo is a legal identifier. If you don't like the behavior, turn off noPropertyAccessFromIndexSignature, this is literally only behavior it controls.
It seems like you're asking for a completely different feature entirely, not describing a defect in NPAFIS
Bug Report
🔎 Search Terms
🕗 Version & Regression Information
problem noticed when
noPropertyAccessFromIndexSignature
started getting used across codebasesPlaygrounds:
5.1.6
nightly
Please keep and fill in the line that best applies:
-->
This is a crashThis changed between versions ______ and _______I was unable to test this on prior versions because _______💻 Code
🙁 Actual behavior
the
noPropertyAccessFromIndexSignature
setting is too aggressive and isn't helpful for objects which use identifier keys🙂 Expected behavior
I almost want there to be a way to specify that keys can be valid identifiers. It seems that
noPropertyAccessFromIndexSignature
is designed to protect against/for/adhere-to-correctness the fact that "string" (as used in the Key in Record, above) means, literally, "any string", which could include non-identifiers, such asfoo bar baz
, orfoo.bar
-- these can be valid keys on an object, but we don't have a way to express that we can manage different kinds of keys.Sure, an object, by default, is "anything goes" with its keys, but the type system has no way to narrow a key to an identifier.
If I could somehow say:
then my problem would be solved, and my example could would provide (non) errors like so:
The text was updated successfully, but these errors were encountered: