typescript-types Questions

4

I am using the latest versions of the mssql package and the @types/mssql package, and my typeRoots directory seems to be correctly set, but I keep getting these errors when trying to compile the Ty...
Fossette asked 14/3, 2018 at 0:1

24

Solved

What is the difference between these statements (interface vs type) in TypeScript? interface X { a: number b: string } type X = { a: number b: string };
Jessabell asked 15/5, 2016 at 1:53

7

I'm building a React Native app using TypeScript. I'm trying to use a SectionList. I followed the docs, and here is my code: renderSectionHeader = ({ section: { title } }: { section: { title: str...

1

I've tried to create a PojoDocument<T> generic type to guard from leaking mongoose documents out of our DALs. My goal was to make sure the returned object is not a mongoose Document, but a PO...

8

Solved

The type should detect if the array has duplicate items and throw error in typescript? type UniqueArray = [ // How to implement this? ] const a:UniqueArray = [1, 2, 3] // success const b:UniqueA...
Beshrew asked 13/7, 2019 at 6:29

3

Solved

// from a library type T = null | "auto" | "text0" | "text1" | "text2" | "text3" | "text4"; //in my code type N = Extract<T, `text${n...
Cortisone asked 7/9, 2021 at 13:56

2

Solved

I want to create a helper function isCallback that returns whether a function is callable. I have a type that can either be true or a callback with a specific argument. In my current code, I have l...
Stark asked 26/11, 2021 at 11:6

2

Solved

Suppose I had the following types type One = 1; type SmallEvens = 0 | 2 | 4 | 6 | 8 | 10; type Three = 3; Is there some kind of type Add<T, U> I could define that adds numbers on the type le...
Yerkovich asked 28/7, 2021 at 21:10

1

Here's the scenario: type Admin = { name : string, privileges : string[] } type Employee ={ name : string, startDate : Date } type ElevatedEmployee = Admin & Employee; const el : Elevated...
Electrostatic asked 13/6, 2022 at 6:53

2

Solved

I have a function that outputs the first letter of the string passed into it. In my case I know what the possible values are, assume either hard-coded or through a generic, and want the function’s ...
Chantellechanter asked 21/7, 2021 at 6:15

3

Solved

Considering an interface IDog with the method likes<T extends IDog>( other: T ). The method takes an argument whose type extends the interface. Why is not allowed to implement that method in ...
Agrimony asked 6/8, 2021 at 12:22

14

Solved

I'm trying to do this: var script:HTMLScriptElement = document.getElementsByName("script")[0]; alert(script.type); but it's giving me an error: Cannot convert 'Node' to 'HTMLScriptElemen...

3

Solved

I was surprised to find that TypeScript won't complain at me doing something like this: type sth = { value: number, data: string } | { value: number, note: string }; const a: sth = { value: 7, data...
Keratoplasty asked 22/9, 2017 at 17:29

2

Solved

Typescript playground I'm having some trouble while trying to wrap my head around the fact that the type never is meaningless and can be discarded when it's inside a union type. I mean, I get that ...

2

Solved

I'm building a React Native app in TypeScript with Redux and Normalizr. So I will have noramlized state. I have four interfaces: Emotion, Need, PainData and PainReport: export interface Emotion {...
Gynaeceum asked 11/10, 2018 at 20:19

2

Solved

I have javascript library with types from npm/@types. I need to make two fixes to @types which applies only in case of my application, so I can't merge them into DefinitelyTyped repository. I ne...

1

Solved

In a Node/TypeScript project if I'm editing the tsconfig.json or package.json file using VSCode then I get some helpful intellisense provided by the editor that it gets from TypeScript. So somewher...

2

Solved

I thought in React it is allowed to assign arrays to styles? Like this: import React from 'react'; import { Text } from "react-native"; // ... render() { const textStyles = [styles.text]; ret...

1

Solved

I'm writing a React app using TypeScript. I use material-ui for my components. I'm writing a custom wrapper for material-ui's Button component. It looks like this: import MUIButton, { ButtonProps ...

1

Solved

I'm writing a React Native application using TypeScript. I have a component EmotionsRater that accepts one of two types: Emotion or Need. It should also either accept a function of type rateNeed o...

1

Solved

Is it in TypeScript somehow possible to define a type so that it only includes objects but not functions? Example: type T = { [name: string]: any } // How to modify this to only accepts objects??...
Anecdotic asked 7/10, 2018 at 20:27

2

Solved

I have two projects (client and server) that should share the same definitions. To achieve this i outsourced my definition (.d.ts) in an extra npm package that I linked back to both projects via np...
Marketing asked 12/6, 2018 at 15:23

1

I'm trying to combine Angular1.5 + Typescript. Installed needed types: npm install @types/angularjs but still see the error: error TS2307: Cannot find module 'angular' Already tried differen...
Arman asked 4/11, 2016 at 9:55
1

© 2022 - 2025 — McMap. All rights reserved.