Skip to content
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

isPropertyReadonlyInType false-positive for rest/spread types #113

Open
ajafff opened this issue Jan 1, 2020 · 2 comments
Open

isPropertyReadonlyInType false-positive for rest/spread types #113

ajafff opened this issue Jan 1, 2020 · 2 comments
Assignees

Comments

@ajafff
Copy link
Owner

ajafff commented Jan 1, 2020

const obj = {const: 1 + 1} as const;
const spreaded = { ...obj };
const constSpreaded = { ...spreaded } as const;
const {...rest} = obj;

obj.const; // readonly
spreaded.const; // writeable
constSpreaded.const; // readonly
rest.const; // writeable
@ajafff
Copy link
Owner Author

ajafff commented Jan 1, 2020

Note to self: This is only relevant for anonymous types.
type.symbol.valueDeclaration can be used to get the node this type originated from. If it's an object literal expression, we only need to look for a const context.
If it's an object binding rest, there's definitely no readonly property.

@ajafff ajafff self-assigned this Jan 1, 2020
@iliubinskii
Copy link

interface SampleInterface {
  readonly x: unknown;
}

const x: SampleInterface = { x: 1 };

const y = { ...x };

For y:
checker.typeToString(type) returns "{ x: unknown; }" which is expected.

However:
tsutils.isReadonlyProperty(type, type.getProperty("x").getEscapedName(), checker) returns "true" which is not expected after spread operator.

Can anything be done about this?
This issue is 2 years old.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants