typescript-definitions

how npm publish typescript interface definition

限于喜欢 提交于 2020-01-25 08:07:34
问题 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 definitions. I've just really started to do TS because another teams need my library to support typings. So let me try to put as much (and as little) detail as I think: tsconfig.json: { "compilerOptions": { "allowSyntheticDefaultImports": true, "allowUmdGlobalAccess": true, "baseUrl": ".",

how does the typescript compiler discover npm packages with types?

余生颓废 提交于 2019-12-25 01:08:52
问题 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” packages are included in your compilation. Packages in node_modules/@types of any enclosing folder are considered visible; specifically, that means packages within ./node_modules/@types/, ../node_modules/@types/, ../../node_modules/@types/, and so on. If typeRoots is specified, only packages under

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

我怕爱的太早我们不能终老 提交于 2019-12-21 16:58:45
问题 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; }; }' is not assignable to parameter of type 'VueClass<Vue>'. Object literal may only specify known properties, and 'template' does not exist in type 'VueClass<Vue>'. My WebStorm IDE did not detect this error; in was outputted in console when I ran Webpack with TypeScript loader. The error occurs in:

Typescript Definitions - nested functions

旧时模样 提交于 2019-12-11 07:33:38
问题 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 take these 3 arguments: S, A, C where S and C are defined in r and A is defined in o . here is a link to the typescript playground which also shows the error I am getting. My question is: How can I get a typesafe declaration? type Task<S, A, C> = <AA extends A>(s: S, a: AA, c: C) => any; type Fn<S,

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

杀马特。学长 韩版系。学妹 提交于 2019-12-06 22:16:35
问题 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 { constructor(mapDiv: Element|null, opts?: MapOptions); fitBounds(bounds: LatLngBounds|LatLngBoundsLiteral): void; ... ... overlayMapTypes: MVCArray<MapType>; } export interface MapOptions { backgroundColor?: string; disableDoubleClickZoom?: boolean; draggable?: boolean; ... When I try to use this type definition in my project,