Menu

first-name is copied into the type draft
📰

first-name is copied into the type draft

DEV Community: laravel·Ameen Usman·6 days ago
#QvtRPRyT
#devtolaravel#devto#dev#name#first
Reading 0:00
15s threshold

A key named first-name looked fine in the JSON. Laravel quotes it, and that array syntax is valid. The TypeScript draft and the PHP DTO copy the hyphen into the field name. first-name: string and public string $first-name are what the converter emits. The constructor uses that same hyphen: $this->first-name = $data['first-name'] ?? null . Nothing in the draft renames the key. The blocks below are that object, converted in the browser.

{ "first-name" : "Ada" , "role" : "engineer" }

Enter fullscreen mode

Exit fullscreen mode

[ 'first-name' => 'Ada' , 'role' => 'engineer' , ]

Enter fullscreen mode

Exit fullscreen mode

export interface Root { first - name : string ; role : string ; }

Enter fullscreen mode

Exit fullscreen mode

<?php

declare ( strict_types = 1 );

class DataTransferObject { public string $first - name ; public string $role ;

public function __construct ( array $data = []) { $this -> first - name = $data [ 'first-name' ] ?? null ; $this -> role = $data [ 'role' ] ??…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.