Should I use interfaces types for the function along with the parameter and return types?





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















This is a function that can be used as the Geolocation API position callback:



const showPosition: PositionCallback = (position: Position): void => console.log(position);


With that PositionCallback, I'd like to know whether should I remove the parameter and return type, or not.










share|improve this question




















  • 1





    Yes: they're redundant. Or no, if you find the code more readable this way.

    – JB Nizet
    Nov 24 '18 at 7:25


















0















This is a function that can be used as the Geolocation API position callback:



const showPosition: PositionCallback = (position: Position): void => console.log(position);


With that PositionCallback, I'd like to know whether should I remove the parameter and return type, or not.










share|improve this question




















  • 1





    Yes: they're redundant. Or no, if you find the code more readable this way.

    – JB Nizet
    Nov 24 '18 at 7:25














0












0








0








This is a function that can be used as the Geolocation API position callback:



const showPosition: PositionCallback = (position: Position): void => console.log(position);


With that PositionCallback, I'd like to know whether should I remove the parameter and return type, or not.










share|improve this question
















This is a function that can be used as the Geolocation API position callback:



const showPosition: PositionCallback = (position: Position): void => console.log(position);


With that PositionCallback, I'd like to know whether should I remove the parameter and return type, or not.







typescript






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 24 '18 at 14:48









Heretic Monkey

6,59063672




6,59063672










asked Nov 24 '18 at 7:09









João LucasJoão Lucas

428




428








  • 1





    Yes: they're redundant. Or no, if you find the code more readable this way.

    – JB Nizet
    Nov 24 '18 at 7:25














  • 1





    Yes: they're redundant. Or no, if you find the code more readable this way.

    – JB Nizet
    Nov 24 '18 at 7:25








1




1





Yes: they're redundant. Or no, if you find the code more readable this way.

– JB Nizet
Nov 24 '18 at 7:25





Yes: they're redundant. Or no, if you find the code more readable this way.

– JB Nizet
Nov 24 '18 at 7:25












2 Answers
2






active

oldest

votes


















1














They are redundant because the definition of PositionCallback specifies the types, so TypeScript is guaranteed to infer them for the right-hand side of the assignment.






share|improve this answer
























  • Would you still use the return and parameters types, even though you know it is redundant, just to improve readability?

    – João Lucas
    Nov 25 '18 at 0:47











  • I don't have a general rule for every case, but yes, I do sometimes keep the types for readability even if they're not required for type checking.

    – dimvar
    Nov 25 '18 at 4:59



















1














It's a matter of style. The types are inferred so the compiler will be happy either way.



The advantage of keeping the PositionCallback type explicit is if the type changes in the future, you compiler will raise errors at all the points where you need to correct the type. Without it you won't get an error until you pass showPosition to something that expects a PositionCallback so it can take a bit longer to fix the code.






share|improve this answer
























  • Would you still use the return and parameters types, even though you know it is redundant, just to improve readability?

    – João Lucas
    Nov 25 '18 at 0:47











  • So, would be better to remove the types for return and parameters, but not otherwise?

    – João Lucas
    Nov 25 '18 at 0:49






  • 1





    @JoãoLucas I would definitely keep the PositionCallback type explicit so I get early compilations errors if something changes. I'd be less likely to keep the explicit types to the right of the equals as my IDE can show me the type if I really need it. However if was an API not being used much the app then I might make them explicit to help people along.

    – matt helliwell
    Nov 25 '18 at 9:31












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53456003%2fshould-i-use-interfaces-types-for-the-function-along-with-the-parameter-and-retu%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














They are redundant because the definition of PositionCallback specifies the types, so TypeScript is guaranteed to infer them for the right-hand side of the assignment.






share|improve this answer
























  • Would you still use the return and parameters types, even though you know it is redundant, just to improve readability?

    – João Lucas
    Nov 25 '18 at 0:47











  • I don't have a general rule for every case, but yes, I do sometimes keep the types for readability even if they're not required for type checking.

    – dimvar
    Nov 25 '18 at 4:59
















1














They are redundant because the definition of PositionCallback specifies the types, so TypeScript is guaranteed to infer them for the right-hand side of the assignment.






share|improve this answer
























  • Would you still use the return and parameters types, even though you know it is redundant, just to improve readability?

    – João Lucas
    Nov 25 '18 at 0:47











  • I don't have a general rule for every case, but yes, I do sometimes keep the types for readability even if they're not required for type checking.

    – dimvar
    Nov 25 '18 at 4:59














1












1








1







They are redundant because the definition of PositionCallback specifies the types, so TypeScript is guaranteed to infer them for the right-hand side of the assignment.






share|improve this answer













They are redundant because the definition of PositionCallback specifies the types, so TypeScript is guaranteed to infer them for the right-hand side of the assignment.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 24 '18 at 14:18









dimvardimvar

506513




506513













  • Would you still use the return and parameters types, even though you know it is redundant, just to improve readability?

    – João Lucas
    Nov 25 '18 at 0:47











  • I don't have a general rule for every case, but yes, I do sometimes keep the types for readability even if they're not required for type checking.

    – dimvar
    Nov 25 '18 at 4:59



















  • Would you still use the return and parameters types, even though you know it is redundant, just to improve readability?

    – João Lucas
    Nov 25 '18 at 0:47











  • I don't have a general rule for every case, but yes, I do sometimes keep the types for readability even if they're not required for type checking.

    – dimvar
    Nov 25 '18 at 4:59

















Would you still use the return and parameters types, even though you know it is redundant, just to improve readability?

– João Lucas
Nov 25 '18 at 0:47





Would you still use the return and parameters types, even though you know it is redundant, just to improve readability?

– João Lucas
Nov 25 '18 at 0:47













I don't have a general rule for every case, but yes, I do sometimes keep the types for readability even if they're not required for type checking.

– dimvar
Nov 25 '18 at 4:59





I don't have a general rule for every case, but yes, I do sometimes keep the types for readability even if they're not required for type checking.

– dimvar
Nov 25 '18 at 4:59













1














It's a matter of style. The types are inferred so the compiler will be happy either way.



The advantage of keeping the PositionCallback type explicit is if the type changes in the future, you compiler will raise errors at all the points where you need to correct the type. Without it you won't get an error until you pass showPosition to something that expects a PositionCallback so it can take a bit longer to fix the code.






share|improve this answer
























  • Would you still use the return and parameters types, even though you know it is redundant, just to improve readability?

    – João Lucas
    Nov 25 '18 at 0:47











  • So, would be better to remove the types for return and parameters, but not otherwise?

    – João Lucas
    Nov 25 '18 at 0:49






  • 1





    @JoãoLucas I would definitely keep the PositionCallback type explicit so I get early compilations errors if something changes. I'd be less likely to keep the explicit types to the right of the equals as my IDE can show me the type if I really need it. However if was an API not being used much the app then I might make them explicit to help people along.

    – matt helliwell
    Nov 25 '18 at 9:31
















1














It's a matter of style. The types are inferred so the compiler will be happy either way.



The advantage of keeping the PositionCallback type explicit is if the type changes in the future, you compiler will raise errors at all the points where you need to correct the type. Without it you won't get an error until you pass showPosition to something that expects a PositionCallback so it can take a bit longer to fix the code.






share|improve this answer
























  • Would you still use the return and parameters types, even though you know it is redundant, just to improve readability?

    – João Lucas
    Nov 25 '18 at 0:47











  • So, would be better to remove the types for return and parameters, but not otherwise?

    – João Lucas
    Nov 25 '18 at 0:49






  • 1





    @JoãoLucas I would definitely keep the PositionCallback type explicit so I get early compilations errors if something changes. I'd be less likely to keep the explicit types to the right of the equals as my IDE can show me the type if I really need it. However if was an API not being used much the app then I might make them explicit to help people along.

    – matt helliwell
    Nov 25 '18 at 9:31














1












1








1







It's a matter of style. The types are inferred so the compiler will be happy either way.



The advantage of keeping the PositionCallback type explicit is if the type changes in the future, you compiler will raise errors at all the points where you need to correct the type. Without it you won't get an error until you pass showPosition to something that expects a PositionCallback so it can take a bit longer to fix the code.






share|improve this answer













It's a matter of style. The types are inferred so the compiler will be happy either way.



The advantage of keeping the PositionCallback type explicit is if the type changes in the future, you compiler will raise errors at all the points where you need to correct the type. Without it you won't get an error until you pass showPosition to something that expects a PositionCallback so it can take a bit longer to fix the code.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 24 '18 at 19:26









matt helliwellmatt helliwell

1,6861016




1,6861016













  • Would you still use the return and parameters types, even though you know it is redundant, just to improve readability?

    – João Lucas
    Nov 25 '18 at 0:47











  • So, would be better to remove the types for return and parameters, but not otherwise?

    – João Lucas
    Nov 25 '18 at 0:49






  • 1





    @JoãoLucas I would definitely keep the PositionCallback type explicit so I get early compilations errors if something changes. I'd be less likely to keep the explicit types to the right of the equals as my IDE can show me the type if I really need it. However if was an API not being used much the app then I might make them explicit to help people along.

    – matt helliwell
    Nov 25 '18 at 9:31



















  • Would you still use the return and parameters types, even though you know it is redundant, just to improve readability?

    – João Lucas
    Nov 25 '18 at 0:47











  • So, would be better to remove the types for return and parameters, but not otherwise?

    – João Lucas
    Nov 25 '18 at 0:49






  • 1





    @JoãoLucas I would definitely keep the PositionCallback type explicit so I get early compilations errors if something changes. I'd be less likely to keep the explicit types to the right of the equals as my IDE can show me the type if I really need it. However if was an API not being used much the app then I might make them explicit to help people along.

    – matt helliwell
    Nov 25 '18 at 9:31

















Would you still use the return and parameters types, even though you know it is redundant, just to improve readability?

– João Lucas
Nov 25 '18 at 0:47





Would you still use the return and parameters types, even though you know it is redundant, just to improve readability?

– João Lucas
Nov 25 '18 at 0:47













So, would be better to remove the types for return and parameters, but not otherwise?

– João Lucas
Nov 25 '18 at 0:49





So, would be better to remove the types for return and parameters, but not otherwise?

– João Lucas
Nov 25 '18 at 0:49




1




1





@JoãoLucas I would definitely keep the PositionCallback type explicit so I get early compilations errors if something changes. I'd be less likely to keep the explicit types to the right of the equals as my IDE can show me the type if I really need it. However if was an API not being used much the app then I might make them explicit to help people along.

– matt helliwell
Nov 25 '18 at 9:31





@JoãoLucas I would definitely keep the PositionCallback type explicit so I get early compilations errors if something changes. I'd be less likely to keep the explicit types to the right of the equals as my IDE can show me the type if I really need it. However if was an API not being used much the app then I might make them explicit to help people along.

– matt helliwell
Nov 25 '18 at 9:31


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53456003%2fshould-i-use-interfaces-types-for-the-function-along-with-the-parameter-and-retu%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Xamarin.form Move up view when keyboard appear

Post-Redirect-Get with Spring WebFlux and Thymeleaf

Anylogic : not able to use stopDelay()