Questions tagged [typescript-definitions]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
0 answers
15 views

make a d.ts file to only override exported enum and return all other original defs?

I am using ReactNativePaper and their fonts/typography unfortunately is not playing along well with custom named text variants. I thought I would try to extend or override the MD3TypescaleKey by ...
Phil Lucks's user avatar
  • 3,056
0 votes
1 answer
42 views

How to specify a monkey patched class in the typescript definitions file?

Say I have a class A: class A { constructor(); someFunction(): void; } and a class B where I expect an instance of class A as a property: class B { aProperty: A; } How can I define ...
frankenapps's user avatar
  • 6,317
1 vote
0 answers
11 views

How To Create A Parent Constructor That Uses Generics To Allow Object Initialization For Children In Typescript?

Okay so I've got a Typescript typing question that I can't quite figure out. I want to create a parent class that allows all inheriting classes to do C# style object initializations. Background ...
IsometricMan's user avatar
0 votes
0 answers
36 views

What are the criteria for .d.ts files to be loaded(/when are they loaded) and from what directories? [duplicate]

Still relative new to Typescript itself and I've been breaking my head on when .d.ts files get loaded. For now I've been putting everything in the src directory with everything else, but that feels ...
Ty Eggen's user avatar
0 votes
0 answers
39 views

Typescript definition file - for a function, return actual property types, or custom property type itself?

I'm trying to write a TypeScript type definitions file for an external JS library, MusicKit JS. I'm fairly new to TS (and especially declaring type definitions in TS). The MusicKit docs are, at times, ...
Scarlet's user avatar
1 vote
0 answers
137 views

Set a JSDoc comment to generate API documentation without adding a TypeScript declaration to the .d.ts file

I'm writing in JS, and I use JSDoc comments to generate both my API documentation and my TypeScript declaration files. However, I have a couple of functions that I'd like to keep out of my TS code -- ...
alec's user avatar
  • 63
2 votes
1 answer
1k views

ESLint: types for `eslintrc.js`

I want my eslintrc.js to be typechecked, and to have all the type definitions of allowed rules builtin. i.e. like: module.exports = defineESLint({ rules: { // intellisence: Enforce the ...
Dimava's user avatar
  • 9,903
0 votes
2 answers
242 views

Right way to document a custom command with then-functionality

Full Typescript Cypress project. I get the following error when trying to use the following custom command in this way: Usage: cy.restGetUserId(userEmail).then(userId => { //do ...
Bambi's user avatar
  • 151
0 votes
1 answer
219 views

Is there a way to use generics to type a complex object array that accurately compares a React component and its props type?

My team has created typescript types definitions for an API that we're using, so we aren't able to touch the source code, just the definitions. We have a function called add that essentially adds one ...
Tim Hunt's user avatar
1 vote
1 answer
563 views

What is the difference between declare var and declare const in typescript definitions?

I recently had a few global variables that I was referencing from a TypeScript file that TypeScript marked with the following error: Property 'msSpeechRecognition' does not exist on type 'Window & ...
Saiansh Singh's user avatar
1 vote
0 answers
254 views

Self-referenced type restriction on inferred type argument in Typescript

I want to have an object builder that should infer types similar to how zod.js does. It should receive fallbacks as an argument and return an object to work with. Fallback could be a value or a ...
Oleksandr Kozlov's user avatar
2 votes
0 answers
174 views

Is there a way to partially declare a module in a definition file?

I'm progressively building a definition file for a library with many exports. I'd like any exports in which I don't provide any definitions for to be typed as any. I know the TypeScript docs recommend ...
Frank Weindel's user avatar
0 votes
1 answer
481 views

How to declare, a module.export which exports an array, in a .d.ts file

I have a node js file that exports an array like const foobar = [{ foo: "bar" }] module.export = foobar How do I write a .d.ts file for this? I tried export declare const foobar: Ifoobar[]...
archuser's user avatar
  • 236
1 vote
0 answers
112 views

Typescript declaration for Node module package

I'm trying to add a TS delcaration for a package i'm using. The package itself doesn't have any TS declarations. I'm using VS Code, and it throws the warning Try `npm i --save-dev @types/picoapp` if ...
Tobias Madsen's user avatar
2 votes
1 answer
590 views

Polyfill type definitions not getting picked up

I'm using TypeScript 4.4.4 and I'm trying to use this EventSource polyfill in my frontend (React): https://github.com/EventSource/eventsource. I've also installed the type definitions for that package....
Victor's user avatar
  • 598
0 votes
0 answers
77 views

Added type definitions library doesn't work with jest

I added @types/google.maps type definitions library to the react application and it works fine everywhere except tests: when I run my jest tests I'm getting "ReferenceError: google is not defined&...
Anna's user avatar
  • 2,971
1 vote
0 answers
60 views

declare function that adheres to type

So I've got a non-typescript project that I'm writing a definition file for. I've got something that looks like this: type SomeType<S> = <T>(operator: (arg: T) => void) => S and I ...
Adam Jenkins's user avatar
  • 52.2k
2 votes
0 answers
182 views

Configure typescript to compile outside of Node or browser [closed]

I'm looking to create a sandboxed JavaScript environment, meaning standard node functions like require() or process.* shouldn't exist. And I would like TypeScript to reflect that. Instead I've got a ...
J-Cake's user avatar
  • 1,536
0 votes
1 answer
324 views

Typescript treat JS array as object

I have a js function that outputs an array with 3 numbers. Could I define a type/interface/whatever that will treat the array as an object. So that Somethig.GetVector().X transpiles into Something....
Matic Babnik's user avatar
3 votes
2 answers
2k views

How to import react-bootstrap component with children into kotlin-js react app

I want to use a bootstrap Card component in a react website created with kotlin-js. The app uses kotlin-react wrapper and react-bootstrap library. react-bootstrap documentation says use <Card.Body&...
tiptop's user avatar
  • 33
2 votes
1 answer
5k views

Vue instance does not pick up shims-vue.d.ts file

I have a Vue file that looks like this: import Vue from 'vue'; import VueRouter from 'vue-router'; export default Vue.extend({ name: 'MyComponentsName', methods: { doRedirect() { this.$...
Matt Grande's user avatar
218 votes
1 answer
102k views

Is it possible to mark something as deprecated in typescript?

I'm writing typescript definitions for a Javascript API with a deprecated method. Here's an extract of the documentation (they say API but it's just about this single method): This API has no effect. ...
lhk's user avatar
  • 28k
1 vote
0 answers
127 views

dts-gen not creating name space issue

Using dts-gen, i am generating a typescript definition file from JavaScript. It is converting all the files properly, except namespace issue. My JavaScript file looks like this.... var Utils = ...
user1862354's user avatar
0 votes
0 answers
240 views

dts-gen ReferenceError: Java is not defined

I am trying to generate TypeScript definition file (.d.ts) from JavaScript file (*.js)...It has converted all the files expect on Java Script file which contains the following statement return Java....
user1862354's user avatar
3 votes
1 answer
1k views

how npm publish typescript interface definition

I have been trying to figure this out for the last 3-4 days, googling and reading a lot, but I don't see any example that contains my use case. I want to npm publish a library that contains its types ...
Danosaure's user avatar
  • 3,608
11 votes
2 answers
10k views

Vue&TypeScript: how to avoid error TS2345 when import implemented in TypeScript component outside of project directory?

I got below TypeScript error when tried to use side component (outside of project directory): TS2345: Argument of type '{ template: string; components: { SimpleCheckbox: typeof SimpleCheckbox; }; }' ...
Takeshi Tokugawa YD's user avatar
4 votes
0 answers
791 views

How to use Phaser 3.17 GameConfig object in Typescript?

After updating Phaser to 3.17 with npm install [email protected] I now get these Typescript errors: const config: GameConfig = { scene: [BootScene, StartScene, GameScene, GameOver], input: { ...
Kokodoko's user avatar
  • 26.5k
1 vote
1 answer
2k views

Typescript Definitions - nested functions

As listed below, let's say we have: a function r that combines multiple tasks together and a function o that returns a shape like when(cb).map(cb) every callback passed to when or map should always ...
Hitmands's user avatar
  • 13.7k
0 votes
1 answer
212 views

how does the typescript compiler discover npm packages with types?

The typescript compiler can be configured via tsconfig.json. This also offers settings for discovering type definition files with the typeRoots key. By default: By default all visible “@types” ...
lhk's user avatar
  • 28k
1 vote
1 answer
361 views

How to create a definition typescript file with a default export and functions inside?

I have to use an internal library to authenticate the users, but now I have to use this lib in a typescript project, so I'm trying to create its definition file (.d.ts), but none of I've tried works. ...
Imac's user avatar
  • 379
0 votes
1 answer
180 views

How to declare an UMD module which only expose one function?

Here's what I currently have: export default function (bar?: any): Foo export as namespace qux; Assuming we have no module loader, what should I change so that qux may be called directly? What I am ...
Knu's user avatar
  • 14.8k
2 votes
2 answers
80 views

What is the right typescript definition for a specific javascript instantiation pattern

I'm currently working on Paper.js library typescript definition and I have trouble finding the right way to document some parts of the API. The case can be reduced to the following: let's say we have ...
sasensi's user avatar
  • 4,630
2 votes
1 answer
1k views

Typescript: use types for explicit import

I'm programming a webextension in Typescript. Since I would like to target both Chrome and Firefox, I need this polyfill. Importing it looks like this: import browser from "webextension-polyfill" ...
lhk's user avatar
  • 28k
1 vote
1 answer
611 views

Object of objects of arrays in Typescript

I have a structure like that and need to make a definitions of types / interfaces for that but I can't make this working properly. layoutsSet: { 1: { "lg": [ { ...
Canor's user avatar
  • 919
5 votes
1 answer
5k views

How to generate type definition file from TypeScript files?

I crafted some classes and modules in TypeScript. Other TypeScript apps can use the TS files directly without needing type definitions. However, to publish to npm, I guess I need to publish both JS ...
ZZZ's user avatar
  • 2,772
2 votes
1 answer
338 views

Define dynamically generated properties from an inherited class

I am trying to generate a d.ts declaration file for my project. There are two classes that do calculate heavy logic, and the remaining classes inherit from them. Properties on the subclasses are not ...
Dov Benyomin Sohacheski's user avatar
1 vote
1 answer
138 views

Distribution of TypeScript definiton files

I have used TypeScript since the beginning and have gone through the iterations of tools and repositories for getting TypeScript definition files (i.e, somelib.d.ts) for Third Party libraries - ...
user210757's user avatar
  • 7,104
3 votes
0 answers
240 views

JavaScript project with global typescript definitions in VS Code?

I have been trying to figure this out for the longest time. Let's say I have a Node.js project that uses .js files. Let's also say that I have a custom definition.d.ts file I want to use to provide ...
topherlicious's user avatar
1 vote
1 answer
83 views

Typescript definition for a class as an object property

I'm putting together a quick .d.ts for a library, but have hit a snag with the following: class Issuer { constructor(metadata) { // ... const self = this; Object....
Frohman's user avatar
  • 111
9 votes
0 answers
891 views

Validate Manually Created Typescript Definition Files

Background I have created a component library using react (plain js). I am in the process of creating Typescript definitions for the components so that consumers of the component library can use the ...
Davie's user avatar
  • 828
0 votes
1 answer
51 views

How to write typescript definition of 3rd party module so that it I can import anything

I have a 3rd party library without typescript definitions. Can I write module declaration that will allow me to import anything from that module? import { Anything } from 'untypedexternalmodule';
Liero's user avatar
  • 25.7k
2 votes
1 answer
246 views

Rework type definitions for analytics-node

There are type definitions for that library that exposes the class Analytics So, sources are the next class Analytics {} module.exports = Analytics Types definitions are good, shortly they are ...
uladzimir's user avatar
  • 5,659
2 votes
0 answers
201 views

Referencing library types in Typescript declaration files (without importing globals)

Background I've been trying to contribute some additions to the Typescript definitions for Mocha. Mocha's Runner inherits from NodeJS EventEmitter. In my .d.ts file, I expressed this by adding: /// &...
Will Westrop's user avatar
26 votes
4 answers
5k views

Typescript interface, function and namespace all have the same name. Which is being exported?

In the Typescript definition file (DefinitelyTyped) I am examining, there is an interface, a function and a namespace all with the exact same name: twilio. Here is the sample, from the first few lines ...
CodyBugstein's user avatar
  • 22.3k
8 votes
1 answer
1k views

How do you import a Typescript type definition file whose top level element is a non-exported namespace?

I'm trying to use the @types/googlemaps type definition file. The code looks like declare namespace google.maps { /***** Map *****/ export class Map extends MVCObject { ...
CodyBugstein's user avatar
  • 22.3k
3 votes
1 answer
162 views

Typescript Definitions can't be imported Angular2

I have been trying to use a typescript definition file from definitely typed and I am having trouble referencing or importing it into the files I want to use it in. The definitions from definitely ...
judisjt's user avatar
  • 43
1 vote
1 answer
2k views

TypeScript typings for a class which is new-able and callable

I'm currently editing the typings for Duplexify. As you can see in Duplexify's source code, Duplexify can be either be a function which returns a new Duplexify instance, or a constructor. In ...
Amit Beckenstein's user avatar
6 votes
1 answer
4k views

Adding properties to existing TypeScript interface via module augmentation has no effect

I have a Node application that depends on @types/hapi. I'd like to add a property to one of the classes defined in this module. I've tried defining my new property via module augmentation: // my-...
Nathan Friend's user avatar
4 votes
1 answer
2k views

dts-gen: fails to find globally installed modules

I have installed dts-gen globally npm i -g dts-gen I installed the target module globally npm i -g jhipster-core When I run dts-gen -m jhipster-core -o I get the following output: Couldn't load ...
vivekmore's user avatar
  • 403
1 vote
0 answers
1k views

React PropTypes throwing instanceof error for class extended with Typescript definitions

I'm running into a problem writing Typescript definitions for a third-party script that's using React PropTypes's instanceof check. Specifically React TimeSeries Charts and PondJS. (They don't have ...
iabw's user avatar
  • 1,108