Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Pôle IS
Bundles Symfony 2
ng-model-generator-bundle
Commits
4d7ce3ac
Commit
4d7ce3ac
authored
Feb 17, 2021
by
Guillaume Perréal
Browse files
ts: définit et utilise un typeguard pour vérifier la présence d'une propriété.
parent
68ac33fc
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/php/Resources/views/repositories.ts.twig
View file @
4d7ce3ac
...
...
@@ -13,6 +13,11 @@ import { {% for name in repoImports %}
{%
-
endfor
%}
} from './resources';
// Simple type guard helper for object with keys
function hasProperty
<T
extends
string
|
number
|
symbol
>
(what: unknown, key: T): what is { [key in T]: any; } {
return typeof what === 'object'
&&
what !== null
&&
key in what;
}
/*********************************************************************************
* Repositories
*********************************************************************************/
...
...
src/php/TypescriptHelper.php
View file @
4d7ce3ac
...
...
@@ -66,7 +66,7 @@ final class TypescriptHelper
*/
public
static
function
propertyTestor
(
string
$object
,
string
$name
):
string
{
return
sprintf
(
'
(%s in %s)'
,
self
::
quoteString
(
$name
)
,
$object
);
return
sprintf
(
'
hasProperty(%s, %s)'
,
$object
,
self
::
quoteString
(
$name
));
}
/**
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment