Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9274837
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T16:26:47+00:00 2026-06-18T16:26:47+00:00

Why doesn’t Typescript warn me that the function I am defining does not match

  • 0

Why doesn’t Typescript warn me that the function I am defining does not match the interface declaration, but it does warn me if I try to invoke the function.

interface IFormatter {
    (data: string, toUpper : boolean): string;
};

//Compiler does not flag error here.
var upperCaseFormatter: IFormatter = function (data: string) {
    return data.toUpperCase();
}  

upperCaseFormatter("test"); //but does flag an error here.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T16:26:48+00:00Added an answer on June 18, 2026 at 4:26 pm

    The interface ensures that all callers of functions that implement the interface supply the required arguments – data and toUpper.

    Because TypeScript understands that JavaScript doesn’t mind if you pass arguments that aren’t used, it cleverly allows this in implementations.

    Why is this okay? Because it means you can substitute any implementation of the interface without affecting calling code.

    Example: You can substitute either IFormatter implementation and the code works.

    interface IFormatter {
        (data: string, toUpper: boolean): string;
    };
    
    var upperCaseFormatter: IFormatter = function (data: string) {
        return data.toUpperCase();
    }
    
    var variableCaseFormatter: IFormatter = function (data: string, toUpper: boolean) {
        if (toUpper) {
            return data.toUpperCase();
        }
    
        return data.toLowerCase();
    }
    
    // Switch between these at will
    //var formatter = upperCaseFormatter;
    var formatter = variableCaseFormatter;
    
    formatter("test", true);
    

    If TypeScript didn’t do this, your upperCaseFormatter would have to have to have a parameter called toUpper that wasn’t used anywhere in the function – which makes the code less readable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Why doesn't copy-namespaces=no remove a namespace declaration that's not referenced in the XSLT's output
It doesn't appear in safari when I preview it, but it does in other
I need a function that will clean a strings' special characters. I do NOT
Doesn't seem that failure mode for that function is documented anywhere I've been able
Doesn't seem to be working for me. I'd open an issue on Github but
Why doesn't this function: test <- function(somebool = FALSE) { mydata<-read.csv(mycsvfile.csv) if(somebool){ print(somebool) summary(mydata)
Why doesn't the following code work? Private Function resolveSiteName(ByVal plantName As String, ByVal siteName
Why doesn't JSON.stringify() display prop2? var newObj = { prop1: true, prop2: function(){ return
Why doesn't this: def subsets(x): if not x: return [[]] else: return [x +
I want to construct a data frame in an Rcpp function, but when I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.