Unable to call a function without a call signature. The type 'moment' does not have any compatible call signatures at position (4,1). TS2349 error needs resolution

I encountered issues with Typescript 3.* and momentjs when working with dates, resulting in compile time errors.

Error:(3, 13) TS2349: Cannot invoke an expression whose type lacks a call signature. Type 'typeof moment' has no compatible call signatures.

To address this error, I sought out a solution and came across an informative article detailing the steps to resolve it.

However, even after following the instructions outlined in the article, I still faced compile time errors.

Error:(1, 8) TS1192: Module '"/Users/hogehoge/Work/Work_Fork/hoge/node_modules/moment/moment"' has no default export.

Below are snippets from my tsconfig file and program code:

{
  "compilerOptions": {
    "moduleResolution": "node",
    "skipLibCheck": false,
    "target": "es5",
    "module": "commonjs",
    "lib": ["es2017", "dom"],
    "experimentalDecorators": true,
    "allowJs": false,
    "jsx": "react",
    "sourceMap": true,
    "strict": true,
    "noImplicitReturns": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "noFallthroughCasesInSwitch": true,
    "esModuleInterop": true,
    "removeComments": true,
    "newLine": "LF",
    "downlevelIteration": true,
    "resolveJsonModule": true,
    "allowSyntheticDefaultImports": false
  },
  "exclude": ["node_modules"]
}

import moment from 'moment';

console.log(moment().format('YYYY-MM-DD'))

Answer №1

Since I didn't have access to your package.json file, I decided to recreate your scenario in the following manner:

npm init
npm i typescript moment @types/node

The code for test.ts:

let moment = require("moment");
console.log(moment().format('YYYY-MM-DD'))

(using require instead of import)

Next, I ran the "compiler":

_modules/.bin/tsc test.ts

Fortunately, there were no errors, and everything worked smoothly for me. At present, the output from the script is 2019-09-30.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Encountered an issue with retrieving schema during self-referencing validation with openapi generator

I created an openapi specification and now I am looking to generate a client for it. openapi.yaml After some research, I decided to use the openapi generator to create a typescript-axios client. This is the command I used: openapi-generator-cli generate ...

TypeScript's Named Type Association

In my project, I have implemented a system that connects names to specific types through a Mapping Object Type called TMap The purpose of this system is to provide a handler function with information about one of the named types along with its correspondi ...

Props used in styled components are effective, although they may trigger a warning message stating, "Warning: Received `true` for a non-boolean attribute `cen`."

Caution: A non-boolean attribute "cen" received a value of "true". If you intend to render it in the DOM, provide a string instead: cen="true" or cen={value.toString()}. While using Props in Styled-Component with TypeScript and Material-UI, everything func ...

How to connect a form component object with a parent object in Vue3 using v-model and the Options API?

My inquiry is quite straightforward. I am exploring the official Vue documentation that delves into v-model arguments in relation to forms within a child component. Here is the code snippet I am referring to: (App.Vue) <script> import UserName from & ...

The potential issue of undefined objects in TypeScript when utilizing computed properties in Vue3

https://i.sstatic.net/I5ZVO.png I've attempted adding a ? after each word and also experimented with the following code: const totalNameLenght = computed(() => { if (userFirstnameLenght.value && userLastnameLenght.value){ ret ...

Ways to transfer data from TypeScript to CSS within Angular 6

Trying to work with ngClass or ngStyle, but I'm struggling with passing the value. Here's my current code: strip.component.ts import { ... } from '@angular/core'; @Component({ selector: 'app-strip', templateUrl: &apo ...

Mastering the art of mocking modules with both a constructor and a function using Jest

I'm a Jest newbie and I've hit a roadblock trying to mock a module that includes both a Class ("Client") and a function ("getCreds"). The Class Client has a method called Login. Here's the code snippet I want to test: import * as sm from &ap ...

Tips for crafting a test scenario for input alterations within Angular

Hello there, currently I am working on an application using Angular and TypeScript. Here is a snippet of my template code: <input type="text" placeholder="Search Results" (input)="searchInput($event)"> And here is the TypeScript code for the searc ...

Tips for efficiently inserting large amounts of data using a select subquery

I'm currently using Sequelize in my project and encountering difficulties in converting a simple query into Sequelize syntax. Furthermore, I am also exploring ways to efficiently perform bulk inserts for this particular query. The query in question i ...

Obtaining Axios response header in a Typescript environment

I am currently working on a rest call that may return a header that I need to store. In order to do this, I have to first check if the header is present before storing it. Here is how I approached it: private getHeader(response: AxiosResponse) { if (r ...

Specialized spinning tool not in sight

Having an angular 11 application with a spinner that should be visible during data loading from the backend. However, when the fa-icon is pressed by the user, it becomes invisible while waiting for the server response. The issue arises when the spinner its ...

How to format a Date object as yyyy-MM-dd when serializing to JSON in Angular?

I have a situation where I need to display an object's 'birthDate' property in the format DD/MM/YYYY on screen. The data is stored in the database as YYYY-MM-DD, which is a string type. I am currently using bootstrap bsDatePicker for this ta ...

Update all occurrences of a particular value to null within the Realtime Database using Firebase Cloud Functions

I need to update the values of a specific userID linked to multiple post keys in my database by setting the userID to null. The userIDs are associated with post keys located in the path: posts/ivies/userIDs in my database. Take a look at how the database i ...

Property 'map' is not recognized on type 'Object' and needs to be addressed

I am currently using Angular CLI: 6.0.8 and have implemented the service shown below. However, my code editor's linter keeps showing an error message that reads: [ts] Property 'map' does not exist on type 'Object'. any The error ...

The 'property' is not found within the type '{ my_function(): void; }'

I am just starting out with TypeScript and VueJS. Currently, I am pondering the best approach for setting the type of a JSON key that should start off as null. <script lang="ts"> import Vue from 'vue'; export default Vue. ...

Testing reactive streams with marble diagrams and functions

Upon returning an object from the Observable, one of its properties is a function. Even after assigning an empty function and emitting the object, the expectation using toBeObservable fails due to a non-deep match. For testing purposes, I am utilizing r ...

Creating personalized functions in Object.prototype using TypeScript

My current situation involves the following code snippet: Object.prototype.custom = function() { return this } Everything runs smoothly in JavaScript, however when I transfer it to TypeScript, an error surfaces: Property 'custom' does not ex ...

What is the best way to effectively handle the proxying of objects across multiple levels?

As illustrated in a Stack Overflow thread, utilizing Proxy objects is an effective method for monitoring changes in an object. But what if you need to monitor changes in subobjects? In such cases, you will also have to proxy those subobjects. I am curren ...

The member 'pipe' is not found within the 'AngularFireObject<{}>' type

As someone new to Angular, I've been following a tutorial by Mosh Hamedani on version 6 of Angular, but unfortunately the tutorial is based on version 4. Currently, I'm working on an e-commerce project that involves implementing an AddToCart butt ...

What is the method for defining functions that accept two different object types in Typescript?

After encountering the same issue multiple times, I've decided it's time to address it: How can functions that accept two different object types be defined in Typescript? I've referred to https://www.typescriptlang.org/docs/handbook/unions ...