Formatter does not work on generic type
See original GitHub issueDescribe the bug
I tried to format a record with generic type 'T
. See below the type definition and register function.
type TestType<'T> =
{
Name: string
Value: 'T
}
let v1:TestType<float> = { Name = "Test"; Value = 1.0 }
let v2:TestType<string> = { Name = "Test"; Value = "String" }
let registerTestType (s:TestType<_>) (writer:TextWriter) =
let headers = new ResizeArray<IHtmlContent> ()
headers.Add(th.innerHTML(i.innerHTML("TestType")))
let rows = ResizeArray<ResizeArray<IHtmlContent>>()
let cells = ResizeArray<IHtmlContent>()
cells.Add(td.innerHTML(s.Name + ": " + (s.Value.ToString())))
rows.Add(cells)
let t =
table.innerHTML(
[|
thead.innerHTML(headers)
tbody.innerHTML(rows.Select(fun r -> tr.innerHTML(r)))
|])
writer.Write(t)
See the screenshot below for the Jupyter output. The following code does not register the format of the generic type
Formatter<TestType<_>>.Register( (fun x writer -> registerTestType x writer), mimeType = "text/html")
I had to register types explicitly to get it working
Formatter<TestType<float>>.Register( (fun x writer -> registerTestType x writer), mimeType = "text/html")
Formatter<TestType<string>>.Register( (fun x writer -> registerTestType x writer), mimeType = "text/html")
Did this error occur while using dotnet try
or online?
-
dotnet-try
- online
What kind of error was it?
- User Interface (UI): For example the output never displayed
- Service Error: For example “The service is temporarily unavailable. We are working on it”
- Other:
Screenshots
Please complete the following:
- OS
- Windows 10
- macOS
- Linux (Please specify distro)
- iOS
- Android
- Browser
- Chrome
- Edge
- Safari
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (7 by maintainers)
Top Results From Across the Web
Problem with using a defined TypeScript Generic Type in ...
First, let's fix that Column<T> definition so it properly types the formatter property. It may be just a typo, but I wanted to...
Read more >Ugly formatting for Typescript generic type type assertion
Heads up I submitted PR #4219 that will fix this if accepted.
Read more >[Code Formatter] lines with declarations with generic types ...
Created attachment 236685 [details] nested classes/methods with generic type parameters that won't wrap The lines in the attached text do not wrap to...
Read more >Generic Formatter Output - Win32 apps
The following table lists the generic format output for PROP_TYPE_BYTE data type properties. In the example output column, the value of the data ......
Read more >Generic Types - Learning the Java Language
A generic type is a generic class or interface that is parameterized over types. The following Box class will be modified to demonstrate...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
We didn’t anticipate this usage but it makes sense. @brettfo and I were discussing how this should be improved.
In C#, this doesn’t compile:
We do have an API that looks like this:
BUT this API doesn’t work yet for non-instantiable types (e.g. interfaces and open generic types).
I’m working on changing that in dotnet/try#611.
Work on the extensibility model is in progress and we’d appreciate feedback. You can see an example here: https://github.com/eerhardt/DotNetInteractiveExtension