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

strong interfaces #1817

Closed
cevek opened this issue Jan 27, 2015 · 5 comments
Closed

strong interfaces #1817

cevek opened this issue Jan 27, 2015 · 5 comments
Labels
Duplicate An existing issue was already created

Comments

@cevek
Copy link

cevek commented Jan 27, 2015

interface IArticle {
    id?: number;
    title: string;
    anons?: string;
    text?: string;
    images?: string[];
}
class Article {
    constructor(params:IArticle) {
        /// some code
    }
}

new Article({id: 1, title: "Title", text: "Hello"});

if I rename property text? to description? in interface IArticle no error occurs
and I dont know what went wrong in my code

How about strong interfaces?

interface strong IArticle {
    id?: number;
    title: string;
    anons?: string;
    text?: string;
    images?: string[];
}

And if object with this interface has over properties then compiler will throw an error

@DanielRosenwasser
Copy link
Member

Can you share the error you're getting and give more code to demonstrate the issue? I'm not able to reproduce any errors with your code.

I'm not sure what you mean by strong interfaces because I can't tell what they're trying to solve.

@AbubakerB
Copy link
Contributor

I think what he means is that if he changes text? in IArticle to description?, then an error should be thrown at:

new Article({id: 1, title: "Title", text: "Hello" /* this doesn't thrown an error - could a strong interface solve this? */ });

Also, applying a comment to this object does something weird .... PLAYGROUND

observe the generated js code.

@cevek
Copy link
Author

cevek commented Jan 27, 2015

Problem is no error occurs if i rename the member text? to description? but i need to know that is may broke my application. Or other frequent example i make typo new Article({tite:123})

@NN---
Copy link

NN--- commented Jan 27, 2015

@cevek Will this code be correct in your case ?

strong interface A {
 name?: string;
}

class B implements A {
 name: string;
 other: number;
}

@RyanCavanaugh
Copy link
Member

See #391

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Jan 27, 2015
@microsoft microsoft locked and limited conversation to collaborators Jun 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

5 participants