type-extension

Typescript Declaration Merging fail about Express Request

南笙酒味 提交于 2021-02-10 06:15:03
问题 When i extend express request, i got this erorr. error TS2339: Property 'test' does not exist on type 'Request<ParamsDictionary, any, any, ParsedQs>'. This is my test code that extend request. app.get('/auth/google/callback', passport.authenticate('google', { failureRedirect: '/login' }), function(req: Request, res: Response) { req.test = 'aa' return console.log(req.test) }); For solving it, i already searched a lot and i did it. Make types/express/index.d.ts file. i add typeRoots in tsconfig

Typescript Declaration Merging fail about Express Request

孤者浪人 提交于 2021-02-10 06:11:46
问题 When i extend express request, i got this erorr. error TS2339: Property 'test' does not exist on type 'Request<ParamsDictionary, any, any, ParsedQs>'. This is my test code that extend request. app.get('/auth/google/callback', passport.authenticate('google', { failureRedirect: '/login' }), function(req: Request, res: Response) { req.test = 'aa' return console.log(req.test) }); For solving it, i already searched a lot and i did it. Make types/express/index.d.ts file. i add typeRoots in tsconfig

F# generating types in a type extension function within a type provider

笑着哭i 提交于 2019-12-13 14:23:28
问题 I have the following problem: Within my type provider, I need to extend a generic type, that I have previously defined, with a method that will return an instance of this generic type. What I mean is, let's say we have : type receiveType<'a> = class val Next:int val Type:string new (state,stateType) = {Next = state;Type = stateType;} end later within my typeprovider I want to extend the type with the following function: [<TypeProvider>] type ProviderTest() as this= ( inherit

Extension method with F# function type

时间秒杀一切 提交于 2019-12-12 11:14:26
问题 The MSDN doc on Type Extensions states that "Before F# 3.1, the F# compiler didn't support the use of C#-style extension methods with a generic type variable, array type, tuple type, or an F# function type as the “this” parameter." (http://msdn.microsoft.com/en-us/library/dd233211.aspx) How can be a Type Extension used on F# function type? In what situations would such a feature be useful? 回答1: Here is how you can do it: [<Extension>] type FunctionExtension() = [<Extension>] static member

F# how to extended the generic array type? [duplicate]

痴心易碎 提交于 2019-12-04 03:24:22
问题 This question already has answers here : How to define a type extension for T[] in F#? (2 answers) Closed 6 years ago . Following this question I wonder how (or if) i can extend the generic F# Array Type. I could do this: type System.Array with member a.Last = a.GetValue(a.Length - 1) but as Tomas mentioned it is non generic. Next I tried this but it does not work: type Microsoft.FSharp.Collections.Array with // Error: Array is not defined member a.Last = a.[a.Length - 1] In the F# scource I

Scoped type variables require explicit foralls. Why?

房东的猫 提交于 2019-12-03 07:32:51
问题 If you want to use GHC's lexically scoped type variables, you also have to use explicit universal quantification. That is, you have to add forall declarations to your functions' type signatures: {-# LANGUAGE ExplicitForAll, ScopedTypeVariables #-} f :: forall a . [a] -> [a] -- The `forall` is required here ... f (x:xs) = xs ++ [x :: a] -- ... to relate this `a` to the ones above. Does this actually have anything to do with quantification, or did the extension writers just coopt the forall

Fun with types! Resolving multiple instance declarations

倾然丶 夕夏残阳落幕 提交于 2019-11-30 09:20:07
问题 I'm trying to write some Haskell code in which there are multiple data types, each of which can have multiple implementations. To do this, I define each data type as a class whose methods are the relevant constructors and selectors, and then implement all operations on members of that class in terms of the given constructors and selectors. For example, perhaps A is a polynomial class (with methods getCoefficients and makePolynomial ) which can have a representation as a SparsePoly or a

Fun with types! Resolving multiple instance declarations

狂风中的少年 提交于 2019-11-29 14:16:10
I'm trying to write some Haskell code in which there are multiple data types, each of which can have multiple implementations. To do this, I define each data type as a class whose methods are the relevant constructors and selectors, and then implement all operations on members of that class in terms of the given constructors and selectors. For example, perhaps A is a polynomial class (with methods getCoefficients and makePolynomial ) which can have a representation as a SparsePoly or a DensePoly and B is a complex number class (with methods getReal , getImag and makeComplex ) which can be