Issue how to use a type as a parameter in Typescript type myType = {} const passingType = (t: Type) => { const x : t = {} } passingType(myType); I get TS errors ‘t’ refers to a value, but
Continue readingTag: typescript-typings
Using an enum and a payload map to get an implicit second argument of undefined
Issue I’m currently writing a function that takes two arguments. The first being the key of an enum, and the second depends on the first argument. Some of the keys don’t require a second argument, so when I assign undefined
Continue readingtypescript conditional typed become union type
Issue try to descript a type for filling data of form item. value’s type depends on type of form item. enum AntdInputType { InputText = ‘InputText’, DatePicker = ‘DatePicker’, TreeSelect = ‘TreeSelect’, // … } type ValueOfTypeMap = { [AntdInputType.InputText]:
Continue readingProperty 'X' is private and only accessible within class 'xyzComponent'
Issue I’m trying to build angular2 application for production for that I’m following this blog. After my ngc successful compilation when the tsc compilation takes place it generates below error shown in the image: After searching for a while I
Continue readingHow to "fill in" generic parameter in typescript
Issue Let’s say I have a generic typescript function like this: function doThing<T>(param: T): T { //… } And I have a concrete interface like this: interface MyType { x: string; y: number; } I want to re-export doThing method
Continue readingtypescript doesn't recognize the result of function
Issue I have created a typescript util that return true if the parameter is a function and false if not, but when I use it to discriminate the way that I use a variable, typescript doesn’t recognize the check. util:
Continue readingIs it possible to create a typescript type from an array?
Issue I often use code such as export type Stuff = ‘something’ | ‘else’ export const AVAILABLE_STUFF: Stuff[] = [‘something’, ‘else’] This way I can both use the type Stuff, and iterate over all the available stuffs if need be.
Continue readingTypescript: enum generic Type as parameter to function
Issue i have a function which takes two parameters one is a key and other is an enum type. I am trying to generalize this function with strong typing to take any enum type and return the value: export const
Continue readinggetting error on form onSubmit because of wrong type in react typescript
Issue I have the below function and when I pass the function into another component I need to define the type of updateChannelInfo but my type is showing wrong, const updateChannelInfo = (event: React.FormEvent<HTMLFormElement>) => { event.preventDefault(); updateTitle(channelTitle); selectedGame &&
Continue readingTypescript optional property type not working on nested prop when it's an array of another type
Issue I made a type that makes all nullable properties optional, even nested ones but for some reason it doesn’t work when given an array of another type. Which is weird because it works when the array is "unwrapped" in
Continue readingHow to use enums for typing in typescript
Issue i’m a bit confused on how to use Enums with TS. Can you use an enum as a value instead of a type? i tried many different ways but i couldn’t solve it. Here’s my code but it doesn’t
Continue readingerror TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index 'ModuleType'
Issue I have types type Link = { type: number | string; productIds: Array<string>; }; export type ModuleType = { ‘@type’: string; title: string; text: string; position: string; backgroundStyle: string; latitude: string; longitude: string; background: File; link: Link; }; const
Continue readingparameter implicitly has an 'any' type
Issue I’m using visual studio code for a typescript project, where I use some 3rd party npm js libraries. Some of them don’t provide any ts types (types.d.ts file), so whenever I use parameters or variables without specifying their type,
Continue readingTypeScript – Distributive conditional types
Issue Talk is cheap,show the code! By the way, the version of ts I am testing is 4.6.4 type ITypeA = ((args: { A: any }) => any) | ((args: { B: any }) => any); type Test<T> = T
Continue readingA namespace-style import cannot be called or constructed, and will cause a failure at runtime
Issue With TypeScript 2.7.2, in VSCode version 1.21 with @types/express and the code that follows, in some cases VSCode throws errors stating that A namespace-style import cannot be called or constructed, and will cause a failure at runtime. However on
Continue readingreact-native/Typescript: how to pass autoComplete value to TextInput as the parent component prop? What's the correct type?
Issue Consider I have a custom component like this with a TextInput inside (for example a modal input dialog): interface Props { … autoComplete: string; } const ModalInputDialog = (props: Props) => { … return (<TextInput autoComplete={props.autoComplete} … />); };
Continue readingvscode typescript: 'Add all missing imports' shortcut
Issue I am working on a typescript project (typescript3.x). I recently noticed the Add all missing imports when I click on the bulb which comes when I am using more than one types which are not yet imported as shown
Continue readingWhat is the difference between Record<K, T> and { [key: K]: T } in TypeScript?
Issue Hi what’s the difference between Record<K, T> and { [key: K]: T } in TypeScript? For example they seem to work the same in the below code. const obj1: Record<string, number> = {a: 1, b: 2}; const obj2: {
Continue readingProperty 'fit' in type Button' is not assignable to the same property in base type 'IButton'. Type 'string' is not assignable to type 'Fit'
Issue I have a class Button, which implements IButton interface. class Button implements IButton { public fit = ‘medium’; } declare type Fit = ‘small’ | ‘medium’ | ‘large’; export interface IButton { fit: Fit; } I would expect to
Continue readingDefine a list of optional keys for Typescript Record
Issue I want to type an object which can only have keys ‘a’, ‘b’ or ‘c’. So I can do it as follows: Interface IList { a?: string; b?: string; c?: string; } They are all optional! Now I was
Continue readingTypeScript character type?
Issue My question is very brief. I am new to TypeScript, been searching around here and there but didn’t find yet an answer. Does any experienced TypeScripter know if there is a character Type or an easy way to achieve
Continue readingTypescript: Changing the definition of some third party types d.ts
Issue I am a little bit lost how to do the following. I am trying to change the definitions of some third party types by creating a new file thirdParty.d.ts. Let’s suppose the third party returns Class A class A
Continue readingtyping toPrimitives interface
Issue I have an interface like this: interface AggregateRoot<Primitives> { toPrimitives(): { [key in keyof Primitives]: any } } And I implement it like this: class Person implements AggregateRoot<Person> { public name public age toPrimitives(): { [key in keyof Person]:
Continue readingFunction argument type inference and conditional type
Issue I’m trying to cover following case: I have a function which accepts a boolean and returns value of RealItem | ImaginaryItem type. I’m using conditional type to narrow the return type based on boolean argument. type RealItem = {
Continue readingExtending Enum in typescript
Issue I was hoping to reuse certain values in enum. Any suggestions of how to achieve such functionality. enum someEnum { a = ‘Some String’, b = 2, }; enum extendedEnum { c = ‘string’, b = someEnum.b } type
Continue readingIs there a type for base64 encoded images in Typescript?
Issue being a Typescript rookie, I am trying to type everything as precisely as possible as a part of the learning process. I have a lqip (low quality image placeholder) property coming from a CMS which should be a base64
Continue readingIs there any significant meaning for `.d.ts` filenames except for readability?
Issue In my project, there’s a shims-vue.d.ts file under src folder: declare module ‘*.vue’ { import type { DefineComponent } from ‘vue’ const component: DefineComponent<{}, {}, any> export default component } Even if I rename shims-vue.d.ts to foo.d.ts, the declarations
Continue readingUse generics to define return value for function with discriminated union as input
Issue I want to create a function that receives an object with updatedAt and/or createdAt properties (as a Date) and returns the same object but with the single or both values serialized as a string. First of all, how do
Continue readingHow to infer first element of a tuple as a tuple type
Issue I’m unable to properly infer the first type of a tuple of arbitrary length as a tuple type, in order to maintain its label: type First1<T extends any[]> = T extends [infer FIRST, …any[]] ? FIRST : never type
Continue readingTypescript: can't extract value type of object with labeled type guard
Issue I don’t know why object value type can’t be extracted properly with generic as below. Could you tell me why it doesn’t work if you know? export type ValueType = { type: "string", value: string, } | { type:
Continue readingIs there some way to "spread" object properties to parameters of a function definition?
Issue Best explained in code: const ROUTE_PARAMS = { userId: ‘userId’, companyId: ‘companyId’, }; // Is this somehow possible? // `typeof` is obviously not the right tool here, just used as an example. function buildRoute(typeof ROUTE_PARAMS): string; // Result should
Continue readingTypeScript function overloading. IDE argument type confusion
Issue I’m trying to achieve good developer experience for my TypeScript API, but I’m facing unexpected issue. When overloading function like shown below: /** Comment 1 */ function a(key: ‘key1’, args: { arg1: number }): string /** Comment 2 */
Continue readingWhy <array>.[n] type are different from <array>.at(n)
Issue I’m trying to switch from using <array>.at() to <array>.[] for consistency. But here is a problem I have run into: const array: string[] = []; if (array[0]) { const item = array[0]; // string } if (array.at(0)) { const
Continue readingHow to make some fields in object required
Issue I need an interface for making some fields of other interface as required. For example: I have IUserInterface: interface IUser { name: string; role?: string; } interface IUserFromDB { id: number; name: string; role: string; } When I create
Continue readingHow can I get type names and member TypeObjects from a ts.TypeObject?
Issue I’m working with a TypeScript compiler to perform some code generation. This is my first time working with the compiler API directly. With some ugly narrowing below (improvement of which I will save for another question), I’m able to
Continue readingHow to use an object with const assertion (as const) as an unique symbol for another type key
Issue I have a list of routes : const N: any = "N"; // get const from non typed lib for example or typed as "string" const PREFIX = `Route_${N}` as const; const Route = { Route1: `${PREFIX}_1`, Route2: `${PREFIX}_2`
Continue readinghow to make an iterable type in type script that has a key value pair
Issue I am using type script and I want to make a type that represents an object like this the keys generated are genrated dynamically how do I do that { dog:true, cat:true, x:true } currently I am just using
Continue readingCreate a global function like jest does
Issue I am working on a meta framework that will use react. I would like to offer some functions that are directly available without the need of an import, exactly like jest does with the function it(), beforeAll() etc… I
Continue readingType for nodejs stream.Stream in typescript?
Issue I’m trying to write typings for a node module that includes a class that inherits from the nodejs stream.Stream class … but I can’t find that class in the typescript NodeJS module. Where is it, and how should I
Continue readingTypescript: can't extract value type of object with labeled type guard
Issue I don’t know why object value type can’t be extracted properly with generic as below. Could you tell me why it doesn’t work if you know? export type ValueType = { type: "string", value: string, } | { type:
Continue readingIs there some way to "spread" object properties to parameters of a function definition?
Issue Best explained in code: const ROUTE_PARAMS = { userId: ‘userId’, companyId: ‘companyId’, }; // Is this somehow possible? // `typeof` is obviously not the right tool here, just used as an example. function buildRoute(typeof ROUTE_PARAMS): string; // Result should
Continue readingWhy <array>.[n] type are different from <array>.at(n)
Issue I’m trying to switch from using <array>.at() to <array>.[] for consistency. But here is a problem I have run into: const array: string[] = []; if (array[0]) { const item = array[0]; // string } if (array.at(0)) { const
Continue readingHow to make some fields in object required
Issue I need an interface for making some fields of other interface as required. For example: I have IUserInterface: interface IUser { name: string; role?: string; } interface IUserFromDB { id: number; name: string; role: string; } When I create
Continue readinghow to make an iterable type in type script that has a key value pair
Issue I am using type script and I want to make a type that represents an object like this the keys generated are genrated dynamically how do I do that { dog:true, cat:true, x:true } currently I am just using
Continue readingHow to use an object with const assertion (as const) as an unique symbol for another type key
Issue I have a list of routes : const N: any = "N"; // get const from non typed lib for example or typed as "string" const PREFIX = `Route_${N}` as const; const Route = { Route1: `${PREFIX}_1`, Route2: `${PREFIX}_2`
Continue readingConstruct type information from string via template literal
Issue Is it possible to construct some type directly from the string provided? I want to create a type something like shown below: type MyConfiguration<T> = { items: T[]; onChange: (updated: ConstructedType<T>) => void; } const conf: MyConfiguration = {
Continue readingHow to use type predicates when using Array.filter with arrow function
Issue I have problem with using type predicates with arrow function. // this working good function filterUndefined1<T>(x: T | undefined): x is T { return !x; } [1, undefined, 3, 5, undefined].filter(filterUndefined1); // Retrun Type Error type FilterUndefined2 = <T>(x:
Continue readingWhere do I get the typescript types of the variable from library
Issue I have been working on a react-typescript project in which I am using a lot of external libraries and I frequently find myself using any type for those libraries. Please look at the code below for the demonstration This
Continue readingTypescript object key with index
Issue I wnat to declare key with index like interface myType { delivery_name1: string; delivery_name2: string; delivery_name3: string; delivery_name4: string; delivery_name5: string; …n(20) } I tried type Index ="1" | "2" | "3" | "4" | "5" | "6" |
Continue readingTuple argument type inference in Typescript
Issue Is it possible to achieve the folowing in Typescript: I want the type of state.initial to be deduced as a tuple based on the input to the takeConfig. It would also be nice to deduce the return type of
Continue readingType 'Dispatch<SetStateAction<any[]>>' is not assignable to type '(values?: string) => void'
Issue I’m very new to typescipt and trying to make a basic pin-input page. Sandbox link for my code . Although it is working, I’m getting this error for onChange function at line 10: Type ‘Dispatch<SetStateAction<any[]>>’ is not assignable to
Continue readingerror TS2306: '…index.d.ts' is not a module
Issue I’m trying to write a lib in Typescript that I want to use in various other typescript or JS projects. All of the those other projects run in browsers. My Typescript lib project has multiple files, and each file
Continue readingDefine an empty object type in TypeScript
Issue I’m looking for ways to define an empty object type that can’t hold any values. type EmptyObject = {} const MyObject: EmptyObject = { thisShouldNotWork: {}, }; Objects with the type are free to add any properties. How can
Continue readingTypeScript typings give me "index.d.ts is not a module"
Issue I am getting File node_modules/@types/webrtc/index.d.ts is not a module with this code: import * as webrtc from “webrtc”; const peerConnection1 = new RTCPeerConnection(); I have installed the typings using npm i @types/webrtc –save-dev. Hovering over RTCPeerConnection in const peerConnection1
Continue readingType 'string | number | symbol' is not assignable to type 'string'
Issue I have a error with following type definition, at L102. Too long url link to read TypeScript 4.6.2 sais… (property) Schema.items?: Schema | undefined Type ‘Schema & p["items"]’ does not satisfy the constraint ‘Schema’. Types of property ‘required’ are
Continue readingHow to access nested conditional type in typescript
Issue The origin of the following autogenerated type is a GraphQL query: export type OfferQuery = { __typename?: ‘Query’ } & { offer: Types.Maybe< { __typename?: ‘Offer’ } & Pick<Types.Offer, ‘id’ | ‘name’> & { payouts: Array< { __typename?: ‘Payout’
Continue readingType 'string | number | symbol' is not assignable to type 'string'
Issue I have a error with following type definition, at L102. Too long url link to read TypeScript 4.6.2 sais… (property) Schema.items?: Schema | undefined Type ‘Schema & p["items"]’ does not satisfy the constraint ‘Schema’. Types of property ‘required’ are
Continue readingType 'string | number | symbol' is not assignable to type 'string'
Issue I have a error with following type definition, at L102. Too long url link to read TypeScript 4.6.2 sais… (property) Schema.items?: Schema | undefined Type ‘Schema & p["items"]’ does not satisfy the constraint ‘Schema’. Types of property ‘required’ are
Continue readingMissing Implicit return type when returning an Enum member in Typescript
Issue Today I came across something interesting at work regarding the return type of a function when using Enum. I have tried to reproduce and make a simple example here. const enum Fruits { Apple, Orange, Kiwi, } function getTest1()
Continue readingMissing Implicit return type when returning an Enum member in Typescript
Issue Today I came across something interesting at work regarding the return type of a function when using Enum. I have tried to reproduce and make a simple example here. const enum Fruits { Apple, Orange, Kiwi, } function getTest1()
Continue readingTyped Indexing variable is not of the same type as the object being indexed
Issue I have a slightly complex object that has typed keys on the top-most level of the object, as well as the deepest level of the object, and I can’t seem to be able to index the second typed keys
Continue readingConditional overloaded method call based on parameter value typescript compilation error TS2322 TS2554
Issue I have a function that take another function as a parameter. The parameter has different signature based on another parameter. I declare the function like this : function edit({ load, onEdit } : { load : true, // options
Continue readingHow to define the value type for example
Issue Example: type ObjProps = { a: string; b: string[] | null; }; type ValueOf<T> = T[keyof T]; const obj: ObjProps = { a: ‘test’, b: null }; type ParamsProps = { propName: keyof ObjProps; value: ValueOf<ObjProps>; } const updateFn
Continue readingTypeScript: Interface cannot simultaneously extends two types
Issue 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 } from “@material-ui/core/Button”; import withStyles, { WithStyles } from
Continue readingTypeScript: Interface cannot simultaneously extends two types
Issue 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 } from “@material-ui/core/Button”; import withStyles, { WithStyles } from
Continue readingConditional overloaded method call based on parameter value typescript compilation error TS2322 TS2554
Issue I have a function that take another function as a parameter. The parameter has different signature based on another parameter. I declare the function like this : function edit({ load, onEdit } : { load : true, // options
Continue readingHow to define the value type for example
Issue Example: type ObjProps = { a: string; b: string[] | null; }; type ValueOf<T> = T[keyof T]; const obj: ObjProps = { a: ‘test’, b: null }; type ParamsProps = { propName: keyof ObjProps; value: ValueOf<ObjProps>; } const updateFn
Continue readingHow to relate different parameters linked by a generic property
Issue I am in the following context: type NumericLiteral = { value: number; type: "NumericLiteral"; }; type StringLiteral = { value: string; type: "StringLiteral"; }; type Identifier = { name: string; type: "Identifier"; }; type CallExpression = { name: string;
Continue readingTypescript | missing property in generic indexable type
Issue I was was curious how Redux Toolkit works under the hood and tried to replicate a basic implementation. But I ran into an issue regarding the indexable type AnyAction and the type PayloadAction that has a defined property called
Continue readingCreating a readonly array from another readonly array
Issue I have an array like this: const arr = [{id: 1, color: "blue"}, {id: 4, color: "red"}] as const and I want to create a type from it that looks like this: type Colors = ["blue", "red"] I’ve tried
Continue readingTypescript | missing property in generic indexable type
Issue I was was curious how Redux Toolkit works under the hood and tried to replicate a basic implementation. But I ran into an issue regarding the indexable type AnyAction and the type PayloadAction that has a defined property called
Continue readingCreating a readonly array from another readonly array
Issue I have an array like this: const arr = [{id: 1, color: "blue"}, {id: 4, color: "red"}] as const and I want to create a type from it that looks like this: type Colors = ["blue", "red"] I’ve tried
Continue readingTypeScript union type cannot be used as an array
Issue This is as far as I was able to reduce the problem to: interface Word { value: string | string[]; } const w: Word = { value: [] as string[] // also tried: // value: [] // value: [‘test’]
Continue readingTypeScript union type cannot be used as an array
Issue This is as far as I was able to reduce the problem to: interface Word { value: string | string[]; } const w: Word = { value: [] as string[] // also tried: // value: [] // value: [‘test’]
Continue readingType a function as such it does return an array of same length
Issue Is there a way to type a function so it says "I take an array of generic type, and will return the same type with the same length" interface FixedLengthArray<T, L extends number> extends Array<T> { length: L; }
Continue readingType a function as such it does return an array of same length
Issue Is there a way to type a function so it says "I take an array of generic type, and will return the same type with the same length" interface FixedLengthArray<T, L extends number> extends Array<T> { length: L; }
Continue readingTypescript creating Object Type from Readonly Array
Issue I have an array like so: const arr = [{id: 2, name: "hotdog"}, {id: 3, name: "chicken"}] as const And I want to generate a type from it, that looks like this: type ArrTransform = { readonly hotdog: 2,
Continue readingTypescript creating Object Type from Readonly Array
Issue I have an array like so: const arr = [{id: 2, name: "hotdog"}, {id: 3, name: "chicken"}] as const And I want to generate a type from it, that looks like this: type ArrTransform = { readonly hotdog: 2,
Continue readingWhat's the difference between (Record<string, unkown>) and object type?
Issue What’s the difference between type Record<string, unkown> and type object? Implement a generic DeepReadonly<T> which make every parameter of an object – and its sub-objects recursively – readonly. I wrote a type: type DeepReadonly<T> = T extends object ?
Continue readingVue.js + Typescript: How to set @Prop type to string array?
Issue What’s the correct way to set the type attribute of the @Prop decorator to Array<string>? Is it even possible? I’m only able to set it to Array without string like so: <script lang="ts"> import { Component, Prop, Vue }
Continue readingTypescript generic how to make typeof object-to-array?
Issue I have this Function export const ObjectToArray = <T>(object: T): { key: any; value: any }[] => Object.entries(object).map(o => ({ key: o[0], value: o[1] })); I want to remove any part of result I even don’t know how to
Continue readingConvert an array of strings into string literal union type
Issue I’m trying to convert an array of strings from the value to the string union type inside a function. But can’t achieve it. Example: const makeGet = (paths: string[]) => (path: typeof paths[number]) => paths.includes(path) const makeGet2 = <T
Continue readingTyping an overloaded class method
Issue I need to write a wrapper around a method foo that is overloaded by parameter type. UPDATE: A extends B UPDATE2: TS playground link const getFoo: { foo(x: number, y?: A): A; foo(x: number, y?: B): B; } In
Continue readingHow can I set up my function arg types to be mutually conditioned upon a config structure?
Issue ### this is my mapping data structure saying: some contexts have specific own tags const config = { contexts: ["A", "B", "C"] as const, tags: { A: ["aa", "bb"] as const, B: ["aa1", "bb1"] as const, C: ["aa2", "bb2"]
Continue readingTypescript merging two object with spread operator and having a resuable type
Issue Hopefully this is a simple enough question but I am having trouble figuring out how to word it in the title. I was making a function that gets and sets a value. And for the setting of the value
Continue readingProperty 'MathFun' is missing in type '(x?: number, y?: number) => number' but required in type 'Func'
Issue Not able to uderstand the error here: Property ‘MathFun’ is missing in type ‘(x?: number, y?: number) => number’ but required in type ‘Func’.(2741) input.tsx(3, 5): ‘MathFun’ is declared here. interface Func { MathFun:(a:number,b:number) => number }; const plus:Func
Continue readingTyped Indexing variable is not of the same type as the object being indexed
Issue I have a slightly complex object that has typed keys on the top-most level of the object, as well as the deepest level of the object, and I can’t seem to be able to index the second typed keys
Continue readingHow to relate different parameters linked by a generic property
Issue I am in the following context: type NumericLiteral = { value: number; type: "NumericLiteral"; }; type StringLiteral = { value: string; type: "StringLiteral"; }; type Identifier = { name: string; type: "Identifier"; }; type CallExpression = { name: string;
Continue readingNPM package cannot be used as a JSX Component – Type errors
Issue Ive been getting these strange type errors on my typescript project for certain packages. Ex: ‘TimeAgo’ cannot be used as a JSX component. Its instance type ‘ReactTimeago<keyof IntrinsicElements | ComponentType<{}>>’ is not a valid JSX element. The types returned
Continue readingHow do I use catchError() and still return a typed Observable with rxJs 6.0?
Issue cdSo I’m trying to migrate some of my Angular 5 code to 6, and I understand most of the changes required for rxjs to work using the .pipe() operator. It works as you would expect for ‘pipable’ operations. However,
Continue readingBroken type inference when extending recursive generic type
Issue I am in the following situation: interface Rec { key: string; children: this[]; } type Recursive<D extends string> = { [K in D]: string; } & Rec; type FlattenRecursive = <D extends string, R extends Recursive<D>>(rs: R[]) => Omit<R,
Continue readingTypeScript React Native Flatlist: How to give renderItem the correct type of it's item?
Issue I’m building a React Native app with TypeScript. renderItem complains that the destructured item implicitly has an any type. I googled and found this question and tried to implement what they teach here combined with the types in index.d.ts
Continue readingTypescript: Limit the number of keys that can be passed via generics and indexed access types for a particular function
Issue Sorry about the title, maybe it’s a little confusing? Let me explain my issue. I’m using a React state management library where I have an application state that looks like the following: type ApplicationState = { loading: boolean; data:
Continue readingHow to type an object with generic keys of different types in typescript
Issue How would you type this objects in typescript ? I have one special "datetime" key that is a Date, the rest of the keys are numbers. But I don’t know in advance which keys will be set on each
Continue readingWhy does TypeScript recursive type alias fail with generics
Issue I’ve got two type definitions describing almost the same thing: // compilation fails with `Type alias ‘StringOrRecordOfStrings’ circularly references itself.ts(2456)` type StringOrRecordOfStrings = string | string[] | Record<string, StringOrRecordOfStrings>; // compiles without problems type StringOrRecordOfStrings = string | string[]
Continue readingHow to read typescript error in order to understand what type should be used?
Issue I don’t understand how to handle typescript error like this. I am using react-navigation and tried to make custom header. From documentation there are list of parameters that this component get but I don’t know how to type check
Continue readingGet the keys of an already typed object as types in typescript
Issue const obj1 = { foo: ‘bar’, goo: ‘car’, hoo: ‘dar’, ioo: ‘far’ } as const const obj2 = { koo: ‘gar’, loo: ‘har’, moo: ‘jar’, noo: ‘kar’ } as const type KeysOfObj1 = keyof typeof obj1 // "foo" |
Continue readingWhat is the correct typescript type for react children?
Issue I’m trying to properly type the props for a component that maps children: type Props = { children: any } const MyComponent: FunctionComponent<Props> = () => (React.Children.map(children, someMapingFunction); I’ve been using JSX.Element but that doesn’t quite feel right. Solution
Continue readingTypeScript $(…).tooltip is not a function
Issue The following error is logged in the console when I try to attach a tooltip. Uncaught TypeError: Uncaught TypeError: $(…).tooltip is not a function My compiler shows me all the tooltip options via intellisense so it seems to be
Continue readingTypescript type A is not assignable to type A (same type)
Issue I’m having an issue where Typescript tells me that type A is not assignable to type A, but they’re exactly the same: Here is a link to the playground: declare interface ButtonInteraction { user: any; customId: string; reply: (message:
Continue reading