Skip to content

Instantly share code, notes, and snippets.

@amakhrov
amakhrov / README.md
Last active May 5, 2022 20:56
Picking a subtype of a union type in Angular templates

Problem

Angular doesn't do type narrowing based on conditions in *ngIf or *ngSwitchCase (angular/angular#20780). And, making it worse, there is no way to write a type assertion directly in a template. With strictInputTypes check turned on it can result in a number of false positive compile time errors.

A common workaround is to have a method in your component that does type assertion, and call this method in a template.

Naive approach

@amakhrov
amakhrov / spec.yml
Created March 26, 2020 18:33
test allOf without discriminator
swagger: '2.0'
info:
description: "This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\"
version: 1.0.0
title: OpenAPI Petstore
license:
name: Apache-2.0
url: 'https://www.apache.org/licenses/LICENSE-2.0.html'
host: petstore.swagger.io:80
basePath: /v2
openapi: 3.0.2
info:
title: TEST
version: "1.0"
paths:
/test:
post:
operationId: test
responses:
200:
swagger: '2.0'
info:
version: '1.0'
title: Example API
schemes:
- http
paths:
/lists:
get:
summary: Endpoint
swagger: '2.0'
info:
version: '1.0'
title: Example API
schemes:
- http
paths:
/map:
get:
summary: Endpoint
swagger: '2.0'
info:
version: '1.0'
title: Example API
schemes:
- http
paths:
/myendpoint1:
get:
summary: Endpoint
swagger: '2.0'
info:
version: '1.0'
title: Example API
schemes:
- http
paths:
/myendpoint1:
post:
summary: Posting inline model 1
swagger: '2.0'
info:
version: '1.0'
title: Example API
schemes:
- http
paths:
/endpoint:
get:
responses:
swagger: '2.0'
info:
title: Test
description: Test
version: 4.0.0
host: crunchbase.com
schemes:
- https
basePath: /v4
produces:
@amakhrov
amakhrov / HtmlComponent.js
Created August 29, 2018 03:35
React HTML rendering
const someHtmlContent = '<strong>highlighted text</strong> and regular text';
const HtmlComponent = () => {
return (
<div>
<h2>Rendering HTML content below</h2>
<div>/* How do you put the html content inside? */</div>
</div>
);
}