Category "typescript"

How to specify (optional) default props with TypeScript for stateless, functional React components?

I'm trying to create a stateless React component with optional props and defaultProps in Typescript (for a React Native project). This is trivial with vanilla J

How to test ng-web-apis/geolocation Observable in angular 8?

I'm trying to test a simple angular 8 service that gets user location using GeoLocation Service from Web APIs for Angular public enableGPS() { if (!this.lo

react-router-dom <Routes> and <BrowserRouter> errors

I am using react-router-dom and am facing an issue with using <Routes>: Here is my index.tsx file: import React from 'react'; import ReactDOM from 'react-

tsc.ps1 cannot be loaded because running scripts is disabled on this system

On PowerShell, I got the error message when executing tsc. This never happened before. I am not sure should I mingle with the PowerShell security settings to r

Input and outputs, how to work with them to follow the naming convention of the Angular 2's styleguide?

Before I knew any better I used to have my directive defined like this: ... inputs: [ 'onOutside' ] ... export class ClickOutsideDirective { @Output() on

How to manage Angular2 "expression has changed after it was checked" exception when a component property depends on current datetime

My component has styles that depend on current datetime. In my component I've got the following function. private fontColor( dto : Dto ) : string { // da

About "*.d.ts" in TypeScript

I am curious about .d.ts declaration files because I am new to the TypeScript programming language. I was told by someone that .d.ts files are are similar to .h

nextjs API with typescript, restricting NextApiRequest query param to just string type [duplicate]

In this endpoint handler, is there a way to restrict req.query in NextJS NextApiRequest to just string types rather than string | string[]. Fo

How do I index only the property names from another object, but leave values to be inferred?

I have the following example joi validation schema const joiUser = { firstName: joi.string().required(), // inferred type: joi.BoxStringSchema<joi.Box<

Chakra UI color mode changes on page refresh, because of system color mode

I'm running NextJS with Chakra UI and the problem is when useSystemColorMode is set to true, it ignores the user's choice on page refresh and sets it back to th

How do I check that a switch block is exhaustive in TypeScript?

I have some code: enum Color { Red, Green, Blue } function getColorName(c: Color): string { switch(c) { case Color.Red: re

Angular/Karma unit test error "1 timer(s) still in the queue"

This is hardly first encounter I've had with "1 timer(s) still in the queue", but usually I find some way to use tick() or detectChanges(), etc., to get out of

the syntax requires an imported helper named __spreadArrays

When I'm trying to use spreading in typescript like: .reduce((unique, x) => { unique.some(element => element.machineName === x.machineName) ? unique

How to avoid this kind of notation " | undefinded " in typescript?

It's not essential, but I'm asking out of curiosity. In Object type we can declare optional property by using ?: operator, but is there a similar shorthand when

Limited parallelism with async/await in Typescript/ES7

I've been experimenting a bit with Typescript, but I'm now a bit stuck on how to use async/await effectively. I'm inserting a bunch of records into a database,

Navigate relative with Angular 2 Router (Version 3)

How to navigate relative from /questions/123/step1 to /questions/123/step2 within a component using Router without string concatenation and specifying /question

(Angular) Watchpack Error (watcher): Error: ENOSPC: System limit for number of file watchers reached

I'm trying to make a project in angular but when I try to compile it shows me these errors over and over till my IDE closes. Watchpack Error (watcher): Error: E

Typescript: Cannot use import statement outside a module

I have a .ts file in node js (latest version of node.js for 07.10.19) app with importing node-module without default export. I use this construction: import { C

Jest: function that should throw does not pass and test will fail

I want to test a function A that calls multiple other functions inside it which can throw errors. Here is an abstraction of my code: // file A.ts const A = (ar

Jest: function that should throw does not pass and test will fail

I want to test a function A that calls multiple other functions inside it which can throw errors. Here is an abstraction of my code: // file A.ts const A = (ar