Skip to content

No warnings when getter/setter is missing from interface type. #33116

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
WORMSS opened this issue Aug 28, 2019 · 10 comments
Closed

No warnings when getter/setter is missing from interface type. #33116

WORMSS opened this issue Aug 28, 2019 · 10 comments
Labels
Duplicate An existing issue was already created

Comments

@WORMSS
Copy link

WORMSS commented Aug 28, 2019

TypeScript Version: 3.4.0-dev.201xxxxx

Search Terms:
type setter no warning, type setter, type getter, type getter setter warning

Code

interface A {
    readonly prop: boolean;
}

const a: A = {
    prop: false
}

const b: A = {
    get prop() {
        return false;
    }
}
const c: A = {
    set prop(value: boolean) {}
}
a.prop = true;
b.prop = true;
c.prop = true;

Expected behavior:
variable b to show warning that it is an incomplete model,
variable c to show warning it's an incomplete model

Actual behavior:
no warnings, but runtime errors Cannot set property prop of #<Object> which has only a getter

Playground Link:
https://www.typescriptlang.org/play/?target=6#code/JYOwLgpgTgZghgYwgAgILIN4Chm+VCOAEwHsQAbAT2QAcoSaAuZAIxJPMJAG4sBfLFgRkAzmGRxm6ALyYceOg2bxyIiP0HCQY1lOSzseZAHMI4xTQAUASjlGjBMAFcoIZCrW8jAgVp0I9A3lcNXN6KwA3OHInCGY2Di5bDB8sOAA6C31kMChY3hZM8Ozc-KEihhK8iG4gA

Related Issues:

Follow-up
I would not expect b to show an error that no setter is supplied if the interface was

interface A {
  readonly prop: boolean;
}

since prop is expected to not have a setter.
And at this point c is completely invalid, but again, still no warnings about c object directly, but atleast Cannot assign to 'prop' because it is a read-only property. is reported for a.prop = true

ts-config

{
  "compilerOptions": {
    /* Basic Options */
    "target": "ESNEXT" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */,
    "strict": true /* Enable all strict type-checking options. */
  }
}
@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Aug 28, 2019
@RyanCavanaugh
Copy link
Member

See #21759 and its linked duplicates, #11596, etc

@WORMSS
Copy link
Author

WORMSS commented Aug 28, 2019

I don't believe this is duplicate. I don't want additional new features. Just want a warning that it's incomplete. If the interface is saying the property is read-write, but the implementation only knows how to read and not write then expect to see an error/warning to say it's incomplete.

@RyanCavanaugh
Copy link
Member

The machinery that would be required to produce that error is #21759.

@WORMSS
Copy link
Author

WORMSS commented Aug 28, 2019

Ok then. The title is very misleading for that then. That a warning for read-only (thing that already exists) would require write-only functionality to be added?

@typescript-bot
Copy link
Collaborator

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

1 similar comment
@typescript-bot
Copy link
Collaborator

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

@WORMSS
Copy link
Author

WORMSS commented Sep 2, 2019

That seems like a duplicate message, how do I mark the bot as a duplicate and close it's message for house-keeping purposes?

@typescript-bot
Copy link
Collaborator

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

1 similar comment
@typescript-bot
Copy link
Collaborator

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

@WORMSS WORMSS closed this as completed Sep 8, 2019
@WORMSS
Copy link
Author

WORMSS commented Sep 11, 2019

Seriously, what the fuck is with this bot? Every 3 days, regardless if the task is open or closed, he keeps messaging..
How do I Delete the issue completely as if it didn't exist?

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants